Skip to content

Commit

Permalink
Support an engine query string parameter without arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjeffburke committed Feb 17, 2020
1 parent de09f78 commit 0eafbf0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/prepareImproQueryString.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const resizeOptions = {
};

const queryStringEngineAndArgsRegex = new RegExp(
`^(${Object.keys(isSupportedEngine).join('|')})=(.*)`
`^(${Object.keys(isSupportedEngine).join('|')})(?:=(.*))?`
);

module.exports = function prepareQueryString(queryString) {
Expand All @@ -29,7 +29,7 @@ module.exports = function prepareQueryString(queryString) {
let m;

if ((m = pair.match(queryStringEngineAndArgsRegex)) !== null) {
const [, engineName, engineArgs] = m;
const [, engineName, engineArgs = ''] = m;
const result = [engineName];
const splitChar = engineArgs.includes('+') ? '+' : ',';
const remaining = engineArgs.split(splitChar);
Expand Down
4 changes: 4 additions & 0 deletions test/prepareImproQueryString.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ describe('prepareImproQueryString', () => {
);
});

it('should parse optipng with no argument', () => {
expect('optipng', 'when prepared to equal', 'optipng');
});

it('should parse pngquant with integer argument correctly', () => {
expect(
'resize=800,800&pngquant=8',
Expand Down

0 comments on commit 0eafbf0

Please sign in to comment.