Skip to content

Commit f7db04f

Browse files
committed
fixes #42
1 parent 22602b6 commit f7db04f

3 files changed

Lines changed: 72 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22

33
<!-- Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. -->
44

5-
## [0.3.0] - 2025-09-12
5+
## [0.3.2] - 2025-12-22
6+
7+
Patch release that fixes some vulnerabilities in dependencies.
8+
9+
### Fixed
10+
- quoted values are now parsed correctly (#42)
11+
12+
## [0.3.1] - 2025-09-12
613

714
### Added
815
- Support to generate SQL statements for querying and modifying database tables (in #41, thanks to @juarezr)

src/parse-table.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,7 @@ function parseTextTable(textString) {
219219
let regex = new RegExp(pattern, 'gm');
220220
let matrix = rows.map((row) => row.split(regex));
221221
let cols = getNumSplitRows(matrix, i);
222-
// Check if the pattern perfectly split all rows with same number of columns
223-
if (cols[0] >= rlen && cols[1] >= rlen) {
224-
return matrix;
225-
}
222+
226223
results[i] = matrix;
227224
columns[i] = cols;
228225
}
@@ -238,7 +235,14 @@ function parseTextTable(textString) {
238235
return row.concat(new Array(diff).fill(""));
239236
}
240237
return row;
241-
});
238+
}).map(row => row.map(cell => {
239+
// Strip surrounding quotes if present
240+
const trimmed = cell.trim();
241+
if (trimmed.startsWith('"') && trimmed.endsWith('"') && trimmed.length >= 2) {
242+
return trimmed.slice(1, -1);
243+
}
244+
return cell;
245+
}));
242246
return normalized;
243247
}
244248

test/quoted-values.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
const assert = require('assert');
2+
const vscode = require('vscode');
3+
const parseTable = require('../src/parse-table');
4+
5+
suite('Quoted Values Parsing Test Suite', () => {
6+
// Mock configuration
7+
const originalGetConfiguration = vscode.workspace.getConfiguration;
8+
9+
setup(() => {
10+
vscode.workspace.getConfiguration = () => ({
11+
get: (key) => {
12+
switch (key) {
13+
case 'decimalPoint': return '10,000.00';
14+
case 'defaultConvention': return 'PascalCase';
15+
default: return null;
16+
}
17+
}
18+
});
19+
});
20+
21+
teardown(() => {
22+
vscode.workspace.getConfiguration = originalGetConfiguration;
23+
});
24+
25+
test('should strip surrounding quotes from numeric values', () => {
26+
const input = 'Col1\n"1"';
27+
const result = parseTable.parseClipboard(input);
28+
29+
// Should catch the issue: currently "1" is parsed as string "1" (with quotes likely kept or treated as string)
30+
// We expect it to be parsed as a number 1
31+
assert.ok(result);
32+
assert.strictEqual(result.data[0][0], 1);
33+
// If it fails, it probably returns "1" (string) or key remains string type
34+
});
35+
36+
test('should strip surrounding quotes from string values', () => {
37+
const input = 'Col1\n"foo"';
38+
const result = parseTable.parseClipboard(input);
39+
40+
assert.ok(result);
41+
assert.strictEqual(result.data[0][0], 'foo');
42+
// If it fails, it probably returns "\"foo\""
43+
});
44+
45+
test('complex row with mixed quoted types', () => {
46+
// From issue description: x Apple Pear Lemon "1"
47+
const input = 'x\tApple\tPear\tLemon\n"1"\t"fruit"\t"fruit"\t"fruit"';
48+
const result = parseTable.parseClipboard(input);
49+
50+
assert.ok(result);
51+
assert.strictEqual(result.headers[0], 'X');
52+
assert.strictEqual(result.data[0][0], 1); // "1" -> 1
53+
assert.strictEqual(result.data[0][1], 'fruit'); // "fruit" -> fruit
54+
});
55+
});

0 commit comments

Comments
 (0)