Skip to content

Commit

Permalink
fix: Double quotes are now escaped when they appear twice.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytetsuro committed Apr 17, 2022
1 parent 51b8629 commit 793afa1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Reporter/CSV/FileBuilder/CSV.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class CSV implements FileBuilder {
),
}
)
.map((row) => header.map((columnName) => (row[columnName] ?? '').replace('"', '""')));
.map((row) => header.map((columnName) => (row[columnName] ?? '').replace(/"/g, '""')));

return [header, ...body];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Reporter/CSV/FileBuilder/__tests__/CSV.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('CSV', () => {

await css.build(
metricsFactory.create(
'/tmp/foo.js|M ba"r 0 3|HB:3 M:90 CC:5 LL:2',
'/tmp/foo.js|M b"a"r 0 3|HB:3 M:90 CC:5 LL:2',
'/tmp/foo.js|M baz 4 6|HB:4 M:30 CC:20 LL:1',
'/tmp/foo.js|F 0 7|LL:3',
'/tmp/bar.js|F 0 3|LL:2',
Expand All @@ -21,7 +21,7 @@ describe('CSV', () => {

expect(writerMock.write.mock.calls[0][1])
.toBe(`${byteOrderMark}"name","fullPath","HalsteadBugsDelivered","Maintainability","CognitiveComplexity","LogicalLineOfCode"
"/tmp/foo.js.dummyClass.ba""r","/tmp/foo.js","3","90","5","2"
"/tmp/foo.js.dummyClass.b""a""r","/tmp/foo.js","3","90","5","2"
"/tmp/foo.js.dummyClass.baz","/tmp/foo.js","4","30","20","1"
"/tmp/bar.js.bar","/tmp/bar.js","5","70","8",""`);
});
Expand Down

0 comments on commit 793afa1

Please sign in to comment.