fix: trim list items before deduplication (#607)

Fixes #606

The List converter now trims items before removing duplicates.
Added unit and browser regression tests for lines that differ only by leading whitespace.
This commit is contained in:
Felipeas authored and GitHub committed 2026-11-30 22:31:31 +01:00
1 parent 4e3b86ba39
commit 302a350b5b
3 files changed
+17 -3

No files matched your search

@@ -37,6 +37,12 @@ test.describe('Tool - List converter', () => {
expect(result.trim()).toEqual("'1', '2', '4', '3', '5'");
});
test('removes duplicates after trimming whitespace', async ({ page }) => {
await page.getByTestId('input').fill('apple\n apple');
await expect(page.getByTestId('area-content')).toHaveText('apple');
});
test('List input should be converted to column output and strip wrappers', async ({ page }) => {
await page.getByTestId('input').fill("('test','test2')");
await page.getByTestId('outputAsColumn').check();
@@ -23,6 +23,14 @@ describe('list-converter', () => {
expect(convert(input, options)).toEqual('"1", "2", "3", "4"');
});
it('should compare trimmed items when removing duplicates', () => {
const input = 'apple\n apple';
const options: ConvertOptions = { itemsSeparator: ', ', removeDuplicates: true };
expect(convert(input, { ...options, trimItems: false })).toEqual('apple, apple');
expect(convert(input, { ...options, trimItems: true })).toEqual('apple');
});
it('should return an empty value for an empty input', () => {
const options: ConvertOptions = {
itemsSeparator: ', ',
@@ -56,15 +56,15 @@ function convert(list: string, options: ConvertOptions): string {
const text = options.lowerCase ? sourceList.toLowerCase() : sourceList;
let parts = text.split(splitRegExp);
if (options.trimItems) {
parts = parts.map((part) => part.trim());
}
if (options.removeDuplicates) {
parts = [...new Set(parts)];
}
if (options.reverseList) {
parts = parts.reverse();
}
if (options.trimItems) {
parts = parts.map((part) => part.trim());
}
parts = parts
.filter((part) => filterRegExp === null || filterRegExp?.test(part))
.filter((part) => notFilterRegExp === null || !notFilterRegExp?.test(part));