-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gatsby): character escape sequences in regex filter in graphql queries #26592
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Thank you.
Regexes are relatively slow and shouldn't be used if performance is a concern. But oh well, if people want to, they should be able to.
// Double escaping is needed to get past the GraphQL parser, | ||
// but single escaping is needed for the RegExp constructor, | ||
// i.e. `"\\\\w+"` for `/\w+/`. | ||
.replace(/\\\\/, `\\`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC this was the actual problem, this regex was missing a global flag?
But I mean if we can drop this entirely that's even better. Will ask @vladar to take a sanity check for graphql.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double escaping my regex stops the errors, but doesn't return any results the same way the graphiql explorer does... Completely out of ideas.
(What's the reason this is in Draft mode?) |
because it depends on apollographql/eslint-plugin-graphql#282 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some context: escaping was added in #11002 and fixed #10989 and #9944
The change makes sense to me but it is potentially a breaking change. For example, take a blog starter with this query:
{
allFile(filter:{relativePath: { regex: "/\\\\.png/" }}) {
nodes {
relativePath
}
}
}
Before this PR it returns a list with a single file. After this PR it returns an empty list (which is what you would expect but it is still a breaking change).
I think we should definitely merge this but maybe as a part of the next major?
yes, makes sense. however, until then we probably should:
sidenote: i believe the original fix in #11002 was just a workaround for the upstream problem in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's get this merged 🚢
hi - can't remember the exact details - but just a heads up that the upstream issue which this pr depended on is still open (and hasn't received any comments). but maybe it's not necessary anymore? |
Thanks for the heads up. I will test this scenario with our latest changes. |
Description
attempt to fix character escape sequences in
regex
filters, i.e. queries like:this is a follow-up to #25047 which was closed prematurely.
replace
ing fromutils/prepare-regex.ts
which is not needed (any more? might have been before the switch away from relay)fs.readFile
). these are not strictly necessary and could be removedeslint-plugin-graphql
which gatsby uses - throws with "Syntax Error: Invalid character escape sequence`. disabling the plugin here makes things work. i have opened fix: support character escape sequences in template literal apollographql/eslint-plugin-graphql#282 upstreamRelated Issues
#25047