mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Tools] Fix line breaks in default JSON serializer (#22653)
* [Tools] Fix line breaks in default JSON serializer * Add test for not escaped line breaks
This commit is contained in:
parent
3d6de7cbc4
commit
4d83cfde56
3 changed files with 11 additions and 12 deletions
|
@ -1,3 +1,8 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`i18n utils should escape linebreaks 1`] = `"Text with\\\\n\\\\n\\\\nline-breaks and \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n "`;
|
||||
exports[`i18n utils should not escape linebreaks 1`] = `
|
||||
"Text
|
||||
with
|
||||
line-breaks
|
||||
"
|
||||
`;
|
||||
|
|
|
@ -30,7 +30,6 @@ import { promisify } from 'util';
|
|||
|
||||
const ESCAPE_LINE_BREAK_REGEX = /(?<!\\)\\\n/g;
|
||||
const HTML_LINE_BREAK_REGEX = /[\s]*\n[\s]*/g;
|
||||
const LINE_BREAK_REGEX = /\n/g;
|
||||
|
||||
export const readFileAsync = promisify(fs.readFile);
|
||||
export const writeFileAsync = promisify(fs.writeFile);
|
||||
|
@ -58,7 +57,7 @@ export function isI18nTranslateFunction(node) {
|
|||
}
|
||||
|
||||
export function formatJSString(string) {
|
||||
return (string || '').replace(ESCAPE_LINE_BREAK_REGEX, '').replace(LINE_BREAK_REGEX, '\\n');
|
||||
return (string || '').replace(ESCAPE_LINE_BREAK_REGEX, '');
|
||||
}
|
||||
|
||||
export function formatHTMLString(string) {
|
||||
|
|
|
@ -44,18 +44,13 @@ describe('i18n utils', () => {
|
|||
test('should remove escaped linebreak', () => {
|
||||
expect(formatJSString('Test\\\n str\\\ning')).toEqual('Test string');
|
||||
});
|
||||
|
||||
test('should escape linebreaks', () => {
|
||||
test('should not escape linebreaks', () => {
|
||||
expect(
|
||||
formatJSString(`Text with
|
||||
|
||||
|
||||
line-breaks and \n\n
|
||||
\n\n
|
||||
`)
|
||||
formatJSString(`Text \n with
|
||||
line-breaks
|
||||
`)
|
||||
).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should detect i18n translate function call', () => {
|
||||
let source = i18nTranslateSources[0];
|
||||
let expressionStatementNode = [...traverseNodes(parse(source).program.body)].find(node =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue