Skip to content

Commit

Permalink
Add support for quoted csv in ini-values
Browse files Browse the repository at this point in the history
  • Loading branch information
shivammathur committed Jan 15, 2021
1 parent d2f5871 commit 6972aed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
11 changes: 11 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ describe('Utils tests', () => {
'b=2',
'c=3'
]);
expect(await utils.CSVArray('\'a=1,2\', "b=3, 4", c=5, d=~e~')).toEqual([
'a=1,2',
'b=3, 4',
'c=5',
"d='~e~'"
]);
expect(await utils.CSVArray('a=\'1,2\', b="3, 4", c=5')).toEqual([
'a=1,2',
'b=3, 4',
'c=5'
]);
expect(await utils.CSVArray('')).toEqual([]);
expect(await utils.CSVArray(' ')).toEqual([]);
});
Expand Down
10 changes: 6 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,7 @@ async function extensionArray(extension_csv) {
return extension
.trim()
.toLowerCase()
.replace('php-', '')
.replace('php_', '');
.replace(/^php[-_]/, '');
})
.filter(Boolean);
}
Expand All @@ -1261,9 +1260,12 @@ async function CSVArray(values_csv) {
return [];
default:
return values_csv
.split(',')
.split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
.map(function (value) {
return value.trim();
return value
.trim()
.replace(/^["']|["']$|(?<==)["']/g, '')
.replace(/=(.*[?{}|&~![()^]+.*)/, "='$1'");
})
.filter(Boolean);
}
Expand Down
12 changes: 7 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,7 @@ export async function extensionArray(
return extension
.trim()
.toLowerCase()
.replace('php-', '')
.replace('php_', '');
.replace(/^php[-_]/, '');
})
.filter(Boolean);
}
Expand All @@ -248,9 +247,12 @@ export async function CSVArray(values_csv: string): Promise<Array<string>> {
return [];
default:
return values_csv
.split(',')
.map(function (value: string) {
return value.trim();
.split(/,(?=(?:(?:[^"']*["']){2})*[^"']*$)/)
.map(function (value) {
return value
.trim()
.replace(/^["']|["']$|(?<==)["']/g, '')
.replace(/=(.*[?{}|&~![()^]+.*)/, "='$1'");
})
.filter(Boolean);
}
Expand Down

0 comments on commit 6972aed

Please sign in to comment.