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

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

fix 'static_url_path' defaulting for empty paths
-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

This comment has been minimized.

Copy link
Member

commented May 25, 2019

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 force-pushed the elbeardmorez:fix_static_url_path branch from 9f5c8cb to ed9ab2d May 25, 2019

@davidism davidism merged commit 754b729 into pallets:master May 25, 2019

12 checks passed

Flask Build #20190525.1 succeeded
Details
Flask (Flask DocsHtml) Flask DocsHtml succeeded
Details
Flask (Flask Pypy3Linux) Flask Pypy3Linux succeeded
Details
Flask (Flask Python27Linux) Flask Python27Linux succeeded
Details
Flask (Flask Python27Windows) Flask Python27Windows succeeded
Details
Flask (Flask Python35Linux) Flask Python35Linux succeeded
Details
Flask (Flask Python36Linux) Flask Python36Linux succeeded
Details
Flask (Flask Python37Linux) Flask Python37Linux succeeded
Details
Flask (Flask Python37Mac) Flask Python37Mac succeeded
Details
Flask (Flask Python37Windows) Flask Python37Windows succeeded
Details
Flask (Flask VersionRange) Flask VersionRange succeeded
Details
Flask (FlaskOnNightly) FlaskOnNightly succeeded
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.