Manually URL re-encode everything so pluses and other regex characters survive. #35
+4
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Queries including regex terms with
+will inadvertently mangle the URL and cause the request to fail, because+is considered a URL-safe character representing space. When they are preserved and interpreted by Scryfall as a space, which is the correct thing for Scryfall to do, they cause the query to appear unterminated in the middle of a regex expression, and then for the URL to have a bunch of garbage at the end.This PR is a bit of a sledgehammer, but it URL-encodes everything from the query that isn't alphanumeric while avoiding double-encoding issues from other attempted solutions. This is both because I was intending to be extremely conservative, and because I wasn't able to find a built-in character set that was more selective (and didn't want to get into the business of defining a custom character set).
I'm unsure how to test this other than to say I have been using it in my project successfully.
I'm also a little surprised that this happens at all; I would have thought that
queryItemswould automatically do the Right Thing with arbitrary strings you give it as arguments but it seems more inclined to just slap them into the URL more or less as-is.