From 90d197d06be890ac5adfccf7f2b70d35812a2b09 Mon Sep 17 00:00:00 2001
From: CrazyMax <crazy-max@users.noreply.github.com>
Date: Sat, 5 Sep 2020 02:52:09 +0200
Subject: [PATCH] Exclude empty items from input list

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
---
 __tests__/context.test.ts | 14 ++++++++++++++
 dist/index.js             |  3 ++-
 src/context.ts            |  6 +++++-
 3 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/__tests__/context.test.ts b/__tests__/context.test.ts
index a86fee5..ce53efc 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 1684221..063f93f 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -13746,7 +13746,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 a2e1a14..6977e3f 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -128,7 +128,11 @@ export async function getInputList(name: string, ignoreComma?: boolean): Promise
   }
   return items
     .split(/\r?\n/)
-    .reduce<string[]>((acc, line) => acc.concat(!ignoreComma ? line.split(',') : line).map(pat => pat.trim()), []);
+    .filter(x => x)
+    .reduce<string[]>(
+      (acc, line) => acc.concat(!ignoreComma ? line.split(',').filter(x => x) : line).map(pat => pat.trim()),
+      []
+    );
 }
 
 export const asyncForEach = async (array, callback) => {