diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts index 63b0ef8..5b2349a 100644 --- a/__tests__/context.test.ts +++ b/__tests__/context.test.ts @@ -15,6 +15,13 @@ describe('getInputList', () => { expect(res).toEqual(['bar', 'baz']); }); + it('remove empty lines correctly', async () => { + setInput('foo', 'bar\n\nbaz'); + const res = await context.getInputList('foo'); + console.log(res); + expect(res).toEqual(['bar', 'baz']); + }); + it('handles comma correctly', async () => { setInput('foo', 'bar,baz'); const res = await context.getInputList('foo'); @@ -22,6 +29,13 @@ describe('getInputList', () => { expect(res).toEqual(['bar', 'baz']); }); + it('remove empty result correctly', async () => { + setInput('foo', 'bar,baz,'); + const res = await context.getInputList('foo'); + console.log(res); + expect(res).toEqual(['bar', 'baz']); + }); + it('handles different new lines correctly', async () => { setInput('foo', 'bar\r\nbaz'); const res = await context.getInputList('foo'); diff --git a/dist/index.js b/dist/index.js index 44c944f..99ca9b1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6594,7 +6594,8 @@ function getInputList(name, ignoreComma) { } return items .split(/\r?\n/) - .reduce((acc, line) => acc.concat(!ignoreComma ? line.split(',') : line).map(pat => pat.trim()), []); + .filter(x => x) + .reduce((acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()), []); }); } exports.getInputList = getInputList; diff --git a/src/context.ts b/src/context.ts index 4a39951..f56e1ad 100644 --- a/src/context.ts +++ b/src/context.ts @@ -35,7 +35,11 @@ export async function getInputList(name: string, ignoreComma?: boolean): Promise } return items .split(/\r?\n/) - .reduce((acc, line) => acc.concat(!ignoreComma ? line.split(',') : line).map(pat => pat.trim()), []); + .filter(x => x) + .reduce( + (acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()), + [] + ); } export const asyncForEach = async (array, callback) => {