Repository navigation
Accept uppercase letters and dots in uri-template variable names - #246
Merged
Merged
Conversation
RFC 6570 defines varchar as ALPHA / DIGIT / "_" / pct-encoded and varname as varchar *( ["."] varchar ). The regex only allowed lowercase letters, no dots and lowercase hex in percent-encoding, so templates such as http://example.com/{userId}, {user.name} and %2F were rejected.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is wrong
The
uri-templateformat rejects valid RFC 6570 templates when a variable name has an uppercase letter or a dot, or when a percent-encoding uses uppercase hex:Expected: all three are valid. RFC 6570 section 2.3:
ALPHAis A-Z and a-z, andHEXDIGinpct-encodedincludes A-F.Cause
fastjsonschema/draft06.py, theuri-templateregex uses[a-z0-9_]for a varchar, has no way to put.inside a name, and uses%[0-9a-f]{2}for percent-encoding (in literals and in names).Fix
Use
[a-zA-Z0-9_]and%[0-9a-fA-F]{2}, and allow a single.between varchars. The varspec part is pulled into a small constant so it is not written twice. Invalid names like{a.},{a..b},{}and{a:0}are still rejected. No backtracking problem: a 150 KB invalid template is checked in a few ms.I also checked it with a small generator of RFC-valid templates (5000 each): before the fix 2897 of 4375 with uppercase names, 2164 of 4606 with uppercase hex and 2629 of 4580 with dotted names were rejected; after the fix 0. Lowercase-only templates were 0 rejected before and after.
Test
Added
test_uri_templateintests/test_format.py(15 cases). 5 of them fail on master and all pass with the fix. Full suite: 5615 passed before, 5630 passed after. Added a CHANGELOG line.