[Graphql] Escape strings (#3143)

When I ran it on all the graphql files of fb, none of them had escape, but someone reported this issue!
master
Christopher Chedeau 2017-11-04 11:04:45 -07:00 committed by GitHub
parent bb145c19c1
commit ec18ebc6c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View File

@ -108,7 +108,7 @@ function genericPrint(path, options, print) {
return n.value;
}
case "StringValue": {
return concat(['"', n.value, '"']);
return concat(['"', n.value.replace(/["\\]/g, "\\$&"), '"']);
}
case "IntValue":
case "FloatValue":

View File

@ -0,0 +1,10 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`string.graphql 1`] = `
query X($a: Int) @relay(meta: "{\\"lowPri\\": true}") { a }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
query X($a: Int) @relay(meta: "{\\"lowPri\\": true}") {
a
}
`;

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "graphql" });

View File

@ -0,0 +1 @@
query X($a: Int) @relay(meta: "{\"lowPri\": true}") { a }