-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 path_template variable parsing containing dots #2440
base: dev
Are you sure you want to change the base?
Conversation
4811dd2
to
995ec65
Compare
995ec65
to
cf185ae
Compare
Maybe I am missing something here, but it seems that the CI tests are quite flaky... |
I don't think it's a bug that you can't use special characters as variable separators as described in #2437. The Pages path template follows the Flask convention for path variables and at this time only supports strings (any text without a slash) in each path segment. The issue with allowing special characters such as a dot or a dash as separators, is that those special characters cannot be used in the variable. In your example, what would happen if
Rather than this custom parsing being handled by dash, I think it would be better to use a path template like |
But flask does support this, you can craft arbitrary URLs using flask path variables, the following splits the parameters just fine: from flask import Flask
app = Flask(__name__)
@app.route('/user/<first>.<last>')
def show_user_profile(first, last):
# show the user profile for that user
return f'Hello {first} {last}'
Well, you can always craft URLs that won't match to a template. Thats the same with all separators, including
Yes, that is possible, but leads to a lot of duplicated code if you split that parameter in many routes. In my application I have a few flask endpoints and some dash endpoints. It just struck me as bug that they are not behaving the same. Maybe the dash pages |
What happens in your tests when you pass
It looks like Flask sticks all the extra ones in the first variable, and everything else is in reverse order based upon a split of the designated separator. |
The code in the PR behaves the same as flask here: It replaces the On second thought i dug a bit more into how flask handles routing, and flask uses |
I'm wondering if switching to Flask can also handle mix and matched separators, heaven forbid, haha. |
It would also make it possible to use converters such as |
I'm in favor of reusing Werkzeug behavior as much as possible. Just be aware that Flask / Werkzeug have a pretty bad record of backward compatibility in areas that we assumed were part of the public API but they choose to remove or alter in minor releases, requiring us to scramble to patch. So if the code being reused is substantial by all means call Werkzeug, but try to find the highest-level reference possible to minimize the likelihood it moves later. If it's small, like just a regex or 2-line function, please inline it so we match their behavior without a risk of later breakage. |
Using dots (
.
) and other special characters as part of apath_template
for pages is currently not supported. This is due to the fact thatpath_template
is passed to Python'sregex
module without escaping first, see #2437.The PR escapes special regex characters in the
path_template
before parsing it. It also simplifies the way the parsing is done by usingre.match
.As
re.escape
on Python 3.6 internally compiles the to-be-escaped string as regex pattern and throws errors for invalid patterns (which we have here), the function keeps a local copy ofre._special_chars_map
to escape these characters.Contributor Checklist
path_template
parsing