Prevent formatting GraphQL embedded in JS if it contains invalid escape sequences (#4278)

This commit is contained in:
Lucas Duailibe authored and GitHub committed 2018-04-07 12:03:56 -03:00
1 parent 01e8e2bb8a
commit a92838facf
3 files changed
+78

No files matched your search

+7
View File
@@ -78,6 +78,13 @@ function embed(path, print, textToDoc /*, options */) {
const isFirst = i === 0;
const isLast = i === numQuasis - 1;
const text = templateElement.value.cooked;
// Bail out if any of the quasis have an invalid escape sequence
// (which would make the `cooked` value be `null` or `undefined`)
if (typeof text !== "string") {
return null;
}
const lines = text.split("\n");
const numLines = lines.length;
const expressionDoc = expressionDocs[i];
@@ -409,6 +409,55 @@ gql\`
`;
exports[`invalid.js 1`] = `
// none of the embedded GraphQL should be formatted
// for they have an invalid escape sequence
gql\`
"\\x"
type Foo {
a: string
}
\`;
gql\`
type Foo {
a: string
}
\${stuff}
"\\x"
type Bar {
b : string
}
\`;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// none of the embedded GraphQL should be formatted
// for they have an invalid escape sequence
gql\`
"\\x"
type Foo {
a: string
}
\`;
gql\`
type Foo {
a: string
}
\${stuff}
"\\x"
type Bar {
b : string
}
\`;
`;
exports[`react-relay.js 1`] = `
const { graphql } = require("react-relay");
+22
View File
@@ -0,0 +1,22 @@
// none of the embedded GraphQL should be formatted
// for they have an invalid escape sequence
gql`
"\x"
type Foo {
a: string
}
`;
gql`
type Foo {
a: string
}
${stuff}
"\x"
type Bar {
b : string
}
`;