mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1142194 - fix quoteString to correctly quote. r=pbrosset
This commit is contained in:
parent
1ba4722af8
commit
6e154c1df1
@ -15,14 +15,26 @@ function quoteString(string) {
|
|||||||
let hasDoubleQuotes = string.contains('"');
|
let hasDoubleQuotes = string.contains('"');
|
||||||
let hasSingleQuotes = string.contains("'");
|
let hasSingleQuotes = string.contains("'");
|
||||||
|
|
||||||
|
let quote = '"';
|
||||||
if (hasDoubleQuotes && !hasSingleQuotes) {
|
if (hasDoubleQuotes && !hasSingleQuotes) {
|
||||||
// In this case, no escaping required, just enclose in single-quotes
|
quote = "'";
|
||||||
return "'" + string + "'";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In all other cases, enclose in double-quotes, and escape any double-quote
|
// Quote special characters as specified by the CSS grammar.
|
||||||
// that may be in the string
|
// See http://www.w3.org/TR/CSS2/syndata.html#tokenization
|
||||||
return '"' + string.replace(/"/g, '\"') + '"';
|
// and http://www.w3.org/TR/CSS2/syndata.html#strings
|
||||||
|
return quote +
|
||||||
|
string.replace(/[\\"]/g, match => {
|
||||||
|
switch (match) {
|
||||||
|
case '\\':
|
||||||
|
return '\\\\';
|
||||||
|
case '"':
|
||||||
|
if (quote == '"')
|
||||||
|
return '\\"';
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
}) +
|
||||||
|
quote;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,7 +155,7 @@ const TEST_DATA = [
|
|||||||
{input: 'content: "this is a \\"string\\""', expected: [{name: "content", value: '\'this is a "string"\'', priority: ""}]},
|
{input: 'content: "this is a \\"string\\""', expected: [{name: "content", value: '\'this is a "string"\'', priority: ""}]},
|
||||||
{input: "content: 'this is a \"string\"'", expected: [{name: "content", value: '\'this is a "string"\'', priority: ""}]},
|
{input: "content: 'this is a \"string\"'", expected: [{name: "content", value: '\'this is a "string"\'', priority: ""}]},
|
||||||
{input: "content: 'this is a \\'string\\'", expected: [{name: "content", value: '"this is a \'string\'"', priority: ""}]},
|
{input: "content: 'this is a \\'string\\'", expected: [{name: "content", value: '"this is a \'string\'"', priority: ""}]},
|
||||||
{input: "content: 'this \\' is a \" really strange string'", expected: [{name: "content", value: '"this \' is a \" really strange string"', priority: ""}]},
|
{input: "content: 'this \\' is a \" really strange string'", expected: [{name: "content", value: '"this \' is a \\\" really strange string"', priority: ""}]},
|
||||||
{
|
{
|
||||||
input: "content: \"a not s\\\
|
input: "content: \"a not s\\\
|
||||||
o very long title\"",
|
o very long title\"",
|
||||||
|
@ -47,6 +47,13 @@ const TEST_DATA = [
|
|||||||
value: "\"content!important\"",
|
value: "\"content!important\"",
|
||||||
priority: ""
|
priority: ""
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: "\"all the \\\"'\\\\ special characters\"",
|
||||||
|
expected: {
|
||||||
|
value: "\"all the \\\"'\\\\ special characters\"",
|
||||||
|
priority: ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user