Skip to content

url parameters casting bytes to str #1502

@fuhrysteve

Description

@fuhrysteve

Hi there! I noticed a change in behavior in werkzeug 0.15.x whereby url parameters used to be safe to send as bytes (on python 3.6).

I apologize for not showing a more direct example in werkzeug, but like most users of werkzeug - I don't use it directly - I use it through flask.

Demonstration (using Flask)

from flask import Flask, url_for

app = Flask(__name__)
app.config['SERVER_NAME'] = 'www.foo.com'


@app.route('/<string:foo>')
def hello(foo):
    return 'Hello, World!'


with app.app_context():
    print(url_for('hello', foo=b'bar'))

With werkzeug<0.15, this will output:

http://www.foo.com/bar

However as of werkzeug>=0.15, it now returns this malformed url:

http://www.foo.com/b%27bar%27

I would expect that if werkzeug isn't going to decode bytes for you anymore, that it ought to raise a TypeError indicating that bytes is no longer safe to pass in.

I hope this example makes sense! Thanks for reviewing my issue - I'd be happy to (attempt to) submit a pull request if y'all agree that this is not desirable behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions