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

fields.Url does not accept file URLs without host #2249

Closed
0xDEC0DE opened this issue Mar 14, 2024 · 1 comment · Fixed by #2800
Closed

fields.Url does not accept file URLs without host #2249

0xDEC0DE opened this issue Mar 14, 2024 · 1 comment · Fixed by #2800

Comments

@0xDEC0DE
Copy link
Contributor

Steps to reproduce

Run this test case:

import marshmallow as mm
class LOL(mm.Schema):
    url = mm.fields.Url(schemes={'file'})

LOL().load(dict(url="file:///var/storage/somefile.zip"))

Expected result

{'url': 'file:///var/storage/somefile.zip'}

Actual behavior

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 756, in loads
    return self.load(data, many=many, partial=partial, unknown=unknown)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 722, in load
    return self._do_load(
           ^^^^^^^^^^^^^^
  File "/Users/nisimond/work/blastarea/lolwut/lib/python3.11/site-packages/marshmallow/schema.py", line 909, in _do_load
    raise exc
marshmallow.exceptions.ValidationError: {'url': ['Not a valid URL.']}

Workaround

This works:

LOL().load(dict(url="file://localhost/var/storage/somefile.zip"))

...but the hostname portion is entirely optional with file URLs.

@sloria sloria changed the title fields.Url does not accept file URLs fields.Url does not accept file URLs without host Jan 21, 2025
@sloria
Copy link
Member

sloria commented Jan 21, 2025

sorry for the delay. i was able to repro the issue. will investigate when i have some time. PRs welcome in the meantime

0xDEC0DE pushed a commit to 0xDEC0DE/marshmallow that referenced this issue Jan 21, 2025
Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue marshmallow-code#2249
0xDEC0DE added a commit to 0xDEC0DE/marshmallow that referenced this issue Jan 21, 2025
Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue marshmallow-code#2249
0xDEC0DE added a commit to 0xDEC0DE/marshmallow that referenced this issue Jan 21, 2025
Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue marshmallow-code#2249
0xDEC0DE added a commit to 0xDEC0DE/marshmallow that referenced this issue Jan 21, 2025
Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue marshmallow-code#2249
0xDEC0DE added a commit to 0xDEC0DE/marshmallow that referenced this issue Jan 21, 2025
Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue marshmallow-code#2249
sloria added a commit that referenced this issue Jan 23, 2025
* fix: add `file` handling to URL fields

Requires a modicum of special handling due to hostnames being
optional.

Fixes: Issue #2249

* Add more tests cases; update changelog

---------

Co-authored-by: Steven Loria <[email protected]>
@sloria sloria closed this as completed Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants