Skip to content

Commit 39e7c83

Browse files
authored
Merge pull request #2892 from thanhlecongg/fix-2891
fix: handle uppercase `file` URLs
2 parents 78a94ea + 8dc078e commit 39e7c83

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/marshmallow/validate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ def __call__(self, value: str) -> str:
214214

215215
# Hostname is optional for file URLS. If absent it means `localhost`.
216216
# Fill it in for the validation if needed
217-
if scheme == "file" and value.startswith("file:///"):
218-
matched = regex.search(value.replace("file:///", "file://localhost/", 1))
217+
if scheme == "file" and value.lower().startswith("file:///"):
218+
matched = regex.search("file://localhost/" + value[8:])
219219
else:
220220
matched = regex.search(value)
221221

tests/test_validate.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ def test_url_custom_scheme_case_insensitive():
224224
"file:///tmp/test%20file.txt",
225225
"file:///",
226226
"file://localhost/",
227+
"FILE:///tmp/tmp1234",
228+
"FILE://localhost/tmp/tmp1234",
229+
"FILE:///C:/Users/test/file.txt",
230+
"FILE://localhost/C:/Program%20Files/file.exe",
231+
"FILE:///home/user/documents/test.pdf",
232+
"FILE:///tmp/test%20file.txt",
233+
"FILE:///",
234+
"FILE://localhost/",
227235
),
228236
)
229237
def test_url_accepts_valid_file_urls(valid_url):

0 commit comments

Comments
 (0)