Skip to content
This repository has been archived by the owner on Sep 24, 2021. It is now read-only.

Commit

Permalink
BugFix for ArgsParser
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-takei committed Apr 17, 2019
1 parent a483ed1 commit 5048b2e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "growi-commons",
"version": "3.2.3",
"version": "3.2.4",
"description": "GROWI Commons Libraries",
"keywords": [
"growi"
Expand Down
5 changes: 5 additions & 0 deletions src/plugin/util/args-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class ArgsParser {
// parse string like 'key1=value1, key2=value2, ...'
// see https://regex101.com/r/pYHcOM/1
const match = arg.match(/([^=]+)=?(.+)?/);

if (match == null) {
return;
}

const key = match[1];
const value = match[2] || true;
options[key] = value;
Expand Down
10 changes: 10 additions & 0 deletions src/test/plugin/util/args-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@ describe('args-parser', () => {
expect(result.options.opt2).toBe('2');
});

test('.parse(\'key, \') returns a valid results', () => {
const result = ArgsParser.parse('key, ');

expect(result.firstArgsKey).toBe('key');
expect(result.firstArgsValue).toBeTruthy();

expect(Object.keys(result.options).length).toBe(1);
expect(result.options.key).toBeTruthy();
});

});

0 comments on commit 5048b2e

Please sign in to comment.