mirror of https://github.com/grafana/grafana
Chore: Correctly escape strings in JSONFormatter (#44096)
* Chore: Properly escape double-quotes in strings in JSONFormatter * escape slashespull/44217/head^2
parent
8ee3f59cd4
commit
bddf3d7558
@ -0,0 +1,45 @@ |
|||||||
|
import { formatString } from './helpers'; |
||||||
|
|
||||||
|
describe('JSONFormatter helpers', () => { |
||||||
|
describe('escapeString', () => { |
||||||
|
it("does not escape strings that don't contain quotes", () => { |
||||||
|
const input = 'hello world'; |
||||||
|
const expected = 'hello world'; |
||||||
|
|
||||||
|
const result = formatString(input); |
||||||
|
expect(result).toEqual(expected); |
||||||
|
}); |
||||||
|
|
||||||
|
it('does not escape strings that contain single quotes', () => { |
||||||
|
const input = `'hello world'`; |
||||||
|
const expected = `'hello world'`; |
||||||
|
|
||||||
|
const result = formatString(input); |
||||||
|
expect(result).toEqual(expected); |
||||||
|
}); |
||||||
|
|
||||||
|
it('does escapes strings that contain one double quote', () => { |
||||||
|
const input = `"hello world`; |
||||||
|
const expected = `\\"hello world`; |
||||||
|
|
||||||
|
const result = formatString(input); |
||||||
|
expect(result).toEqual(expected); |
||||||
|
}); |
||||||
|
|
||||||
|
it('does escapes strings that contain two double quotes', () => { |
||||||
|
const input = `"hello world"`; |
||||||
|
const expected = `\\"hello world\\"`; |
||||||
|
|
||||||
|
const result = formatString(input); |
||||||
|
expect(result).toEqual(expected); |
||||||
|
}); |
||||||
|
|
||||||
|
it('does escapes a string that looks like JSON', () => { |
||||||
|
const input = `{"hello": "world"}`; |
||||||
|
const expected = `{\\"hello\\": \\"world\\"}`; |
||||||
|
|
||||||
|
const result = formatString(input); |
||||||
|
expect(result).toEqual(expected); |
||||||
|
}); |
||||||
|
}); |
||||||
|
}); |
Loading…
Reference in new issue