Skip to content

Redirect URLs with # don't work #37

@graue

Description

@graue

If you have a track or album image with a literal # in its path, it won't play/show.

This is proving surprisingly annoying to fix (i.e., it's taken more than 15 minutes and I haven't fixed it yet). On the one hand, Flask doesn't escape the #, so it's getting treated as an anchor and not sent over HTTP as part of the path. On the other hand, if you manually escape the # to %23, Flask thwarts you by escaping the percent sign. Furthermore, writing your own redirect function analogous to flask.redirect isn't enough, as the location header isn't escaped there.

Thanks to smaili on Stack Overflow, I found out the URL escaping is getting done in get_wsgi_headers in Werkzeug here. The code, inside the BaseResponse class, checks self.autocorrect_location_header and runs only if that's true. So maybe I can write my own redirect function, but I'll have to

  1. set the created response object's autocorrect_location_header to false,
  2. manually do something like what autocorrect_location_header does, so that spaces become %20, relative URLs become absolute, etc. — just with the difference of also escaping #.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions