Skip to content

Commit

Permalink
fix: double quotes in string not escaped properly #73
Browse files Browse the repository at this point in the history
close #73
  • Loading branch information
urish committed Nov 28, 2021
1 parent 910143b commit 47c105c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/spectra.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ describe('spectra', () => {
expect(encodeObject(['foo', 'bar'])).toEqual('(foo bar)');
});

it('should escape quotes in strings', () => {
expect(encodeObject(['0.96" OLED'])).toEqual('("0.96\\" OLED")');
});

it('should ignore null values', () => {
expect(encodeObject(['foo', null, 'bar'])).toEqual('(foo bar)');
});
Expand Down
2 changes: 1 addition & 1 deletion src/spectra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function encodeString(str: string) {
if (/^[a-z][a-z0-9_]+$/.test(str)) {
return str;
}
return `"${str.replace(/"/g, '""')}"`;
return `"${str.replace(/"/g, '\\"')}"`;
}

function encodeNumber(value: number) {
Expand Down

0 comments on commit 47c105c

Please sign in to comment.