The label printer integration stores the location of each template as a file URL. Almost every such URL has an empty host, as in file:///etc/hosts, and the URL validator refuses them even when file is among the allowed s…
The label printer integration stores the location of each template as a file URL. Almost every such URL has an empty host, as in file:///etc/hosts, and the URL validator refuses them even when file is among the allowed schemes. Only the rarely used form with an explicit host passes.
from marshmallow import validate
validate.URL(schemes={"file"})("file:///etc/hosts")
validate.URL(schemes={"http", "https", "file"})("file:///C:/Users/x/report.pdf")
Both return the URL.
Both raise ValidationError: Not a valid URL.
file URL the host is optional. An empty host means the local machine, the same as file://localhost/etc/hosts, which already validates.file:// on its own is not valid, and neither is file:/etc/hosts.file. http:///etc/hosts stays invalid, also when file is one of the allowed schemes.file is not among the default schemes, so validate.URL()("file:///etc/hosts") stays invalid.Adapted from marshmallow-code/marshmallow (MIT).
Visible test command
pytest testsThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
file-urls-without-host-rejected
Changes under src/ are evaluated.