Skip to content

Commit

Permalink
Ensure getDelimitedInput handles trailing delimiters correctly (#60)
Browse files Browse the repository at this point in the history
* Ensure getDelimitedInput handles trailing delimiters correctlyFixes #59

* Adding missing newline that's bothering me

* Re-ordering filter (c/o @karoun)
  • Loading branch information
cooperbenson-qz authored Nov 24, 2020
1 parent 821aa8e commit 84d374d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/utils/__tests__/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,22 @@ describe('getDelimitedArrayInput', () => {
expect(getDelimitedArrayInput(key)).toStrictEqual(value);
expect(mockGetInput).toHaveBeenCalledWith(key, undefined);
});

it('ignores trailing commas', () => {
const key = 'input';
const value = ['foo', 'bar', 'baz'];
const rawValue = `${_.join(value, ',')},`;
mockGetInput.mockReturnValueOnce(rawValue);
expect(getDelimitedArrayInput(key)).toStrictEqual(value);
expect(mockGetInput).toHaveBeenCalledWith(key, undefined);
});

it('ignores trailing newlines', () => {
const key = 'input';
const value = ['foo', 'bar', 'baz'];
const rawValue = `${_.join(value, '\n')}\n`;
mockGetInput.mockReturnValueOnce(rawValue);
expect(getDelimitedArrayInput(key)).toStrictEqual(value);
expect(mockGetInput).toHaveBeenCalledWith(key, undefined);
});
});
2 changes: 1 addition & 1 deletion src/utils/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export function getDelimitedArrayInput(name: string, options?: InputOptions): st
const value = getInput(name, options);
const sep = _.includes(value, '\n') ? '\n' : ',';
// eslint-disable-next-line @typescript-eslint/unbound-method
return _.map(_.split(value, sep), _.trim);
return _.filter(_.map(_.split(value, sep), _.trim));
}

0 comments on commit 84d374d

Please sign in to comment.