Skip to content

Commit 2cd9f5e

Browse files
committed
MergeCommand: when handling --input-file-(nul-)list, avoid adding duplicates and empty lines, if any
Signed-off-by: Jim Klimov <[email protected]>
1 parent 89499f5 commit 2cd9f5e

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/cyclonedx/Commands/MergeCommand.cs

+16-4
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,14 @@ public static async Task<int> Merge(MergeCommandOptions options)
8686
{
8787
Console.WriteLine($"Adding to input file list from " + OneInputFileList);
8888
string[] lines = File.ReadAllLines(OneInputFileList);
89-
InputFiles.AddRange(lines);
90-
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
89+
int count = 0;
90+
foreach (string line in lines) {
91+
if (string.IsNullOrEmpty(line)) continue;
92+
if (InputFiles.Contains(line)) continue;
93+
InputFiles.Add(line);
94+
count++;
95+
}
96+
Console.WriteLine($"Got " + count + " new entries from " + OneInputFileList);
9197
}
9298
}
9399

@@ -99,8 +105,14 @@ public static async Task<int> Merge(MergeCommandOptions options)
99105
{
100106
Console.WriteLine($"Adding to input file list from " + OneInputFileList);
101107
string[] lines = File.ReadAllText(OneInputFileList).Split('\0');
102-
InputFiles.AddRange(lines);
103-
Console.WriteLine($"Got " + lines.Length + " entries from " + OneInputFileList);
108+
int count = 0;
109+
foreach (string line in lines) {
110+
if (string.IsNullOrEmpty(line)) continue;
111+
if (InputFiles.Contains(line)) continue;
112+
InputFiles.Add(line);
113+
count++;
114+
}
115+
Console.WriteLine($"Got " + count + " new entries from " + OneInputFileList);
104116
}
105117
}
106118

0 commit comments

Comments
 (0)