Skip to content
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 'static_url_path' defaulting for empty paths #3124

Merged
merged 2 commits into from
May 25, 2019

Conversation

elbeardmorez
Copy link
Contributor

@elbeardmorez elbeardmorez commented Mar 18, 2019

the documentation of the application object specifies static parameters:

static_url_path – can be used to specify a different path for the static
files on the web. Defaults to the name of the static_folder folder.

static_folder – the folder with static files that should be served at
static_url_path. Defaults to the 'static' folder in the root path of the
application.

so by my understanding,

app=Flask(__name__, static_folder='')

should allow for arbitrary (absolute) path structure for all static
files. it doesn't. but the following does:

app=Flask(__name__, static_folder='', static_url_path='')

given the above doc strings, that appears inconsistent

for this specific case (static_folder=''), stepping through the
codebase yielded:

<Rule '//' (GET, OPTIONS, HEAD) -> static>
re.compile('^\\|//(?P<filename>[^/].*?)$')

which is an expression that can never be satisfied by a valid url

please consider this trivial patch. i hope the tests are appropriate
too, it was difficult to know how much of the mechanism to incorporate
for such a small change

commit message:

-prefix a path delimiter iff there's a path to delimit
-ensures a valid default static route rule is created on application
intialisation for the case 'static_folder=""' and implicit
'static_url_path'

todo

  • add a changelog entry if this patch changes code

@davidism davidism modified the milestone: 1.1 May 17, 2019
-prefix a path delimiter iff there's a path to delimit
-ensures a valid default static route rule is created on application
intialisation for the case 'static_folder=""' and implicit
'static_url_path'
@davidism
Copy link
Member

It looks like this was addressed in a different way by #3182, but this solution seems more correct.

flask/helpers.py Outdated Show resolved Hide resolved
@davidism davidism added this to the 1.1.0 milestone May 25, 2019
@davidism davidism merged commit 754b729 into pallets:master May 25, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants