parent
1046fe0455
commit
fbc770c804
|
|
@ -62,12 +62,8 @@ function yamlStringNeedsQuotes(str: string): boolean {
|
||||||
if (/^-\s/.test(str))
|
if (/^-\s/.test(str))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Strings that start with a special indicator character need quotes
|
// Strings containing ':' or '\n' followed by a space or at the end need quotes
|
||||||
if (/^[&*\],].*/.test(str))
|
if (/[\n:](\s|$)/.test(str))
|
||||||
return true;
|
|
||||||
|
|
||||||
// Strings containing ':' followed by a space or at the end need quotes
|
|
||||||
if (/:(\s|$)/.test(str))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Strings containing '#' preceded by a space need quotes (comment indicator)
|
// Strings containing '#' preceded by a space need quotes (comment indicator)
|
||||||
|
|
@ -78,21 +74,17 @@ function yamlStringNeedsQuotes(str: string): boolean {
|
||||||
if (/[\n\r]/.test(str))
|
if (/[\n\r]/.test(str))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Strings starting with '?' or '!' (directives) need quotes
|
// Strings starting with indicator characters or quotes need quotes
|
||||||
if (/^[?!]/.test(str))
|
if (/^[&*\],?!>|@"'#%]/.test(str))
|
||||||
return true;
|
|
||||||
|
|
||||||
// Strings starting with '>' or '|' (block scalar indicators) need quotes
|
|
||||||
if (/^[>|]/.test(str))
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Strings starting with quotes need quotes
|
|
||||||
if (/^["']/.test(str))
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Strings containing special characters that could cause ambiguity
|
// Strings containing special characters that could cause ambiguity
|
||||||
if (/[{}`]/.test(str))
|
if (/[{}`]/.test(str))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// Non-string types recognized by YAML
|
||||||
|
if (!isNaN(Number(str)) || ['y', 'n', 'yes', 'no', 'true', 'false', 'on', 'off', 'null'].includes(str.toLowerCase()))
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -509,3 +509,57 @@ it('should handle long strings', async ({ page }) => {
|
||||||
- region: ${s}
|
- region: ${s}
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should escape special yaml characters', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<a href="#">@hello</a>@hello
|
||||||
|
<a href="#">]hello</a>]hello
|
||||||
|
<a href="#">hello\n</a>
|
||||||
|
hello\n<a href="#">\n hello</a>\n hello
|
||||||
|
<a href="#">#hello</a>#hello
|
||||||
|
`);
|
||||||
|
|
||||||
|
await checkAndMatchSnapshot(page.locator('body'), `
|
||||||
|
- link "@hello"
|
||||||
|
- text: "@hello"
|
||||||
|
- link "]hello"
|
||||||
|
- text: "]hello"
|
||||||
|
- link "hello"
|
||||||
|
- text: hello
|
||||||
|
- link "hello"
|
||||||
|
- text: hello
|
||||||
|
- link "#hello"
|
||||||
|
- text: "#hello"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should escape special yaml values', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<a href="#">true</a>False
|
||||||
|
<a href="#">NO</a>yes
|
||||||
|
<a href="#">y</a>N
|
||||||
|
<a href="#">on</a>Off
|
||||||
|
<a href="#">null</a>NULL
|
||||||
|
<a href="#">123</a>123
|
||||||
|
<a href="#">-1.2</a>-1.2
|
||||||
|
<input type=text value="555">
|
||||||
|
`);
|
||||||
|
|
||||||
|
await checkAndMatchSnapshot(page.locator('body'), `
|
||||||
|
- link "true"
|
||||||
|
- text: "False"
|
||||||
|
- link "NO"
|
||||||
|
- text: "yes"
|
||||||
|
- link "y"
|
||||||
|
- text: "N"
|
||||||
|
- link "on"
|
||||||
|
- text: "Off"
|
||||||
|
- link "null"
|
||||||
|
- text: "NULL"
|
||||||
|
- link "123"
|
||||||
|
- text: "123"
|
||||||
|
- link "-1.2"
|
||||||
|
- text: "-1.2"
|
||||||
|
- textbox: "555"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue