Skip to content

bugfix/escape-http-url-paths - #90

Open
rpinho wants to merge 1 commit into
bioio-devs:mainfrom
rpinho:bugfix/escape-http-url-paths
Open

rpinho wants to merge 1 commit into
bioio-devs:mainfrom
rpinho:bugfix/escape-http-url-paths

Conversation

@rpinho

@rpinho rpinho commented Nov 26, 2026

Copy link
Copy Markdown

Link to Relevant Issue

Addresses bioio-devs/bioio#239.

Who hits this: bioio / bioio-czi users opening HTTP(S) image URLs whose path contains literal spaces or non-ASCII characters (bioio-devs/bioio#239).

Description of Changes

pathlike_to_fs() currently returns http:// and https:// URLs with literal spaces untouched. While fsspec/aiohttp escape those paths internally when fetching (so TIFF/OME-TIFF reads succeed), readers that hand the returned URL straight to a native HTTP client (such as bioio-czi passing the URL to aicspylibczi's libCZI curl stream) fail with curl_url_set(..) failed with error code 3 (Malformed input to a URL function) before any request is sent.

Changes:

  • In bioio_base/io.py (pathlike_to_fs), percent-encode only the path component of http:// and https:// URLs using urllib.parse.quote(..., safe="/%:@!$&'()*+,;=[]"), matching the path directly so literal tabs/newlines are encoded rather than stripped by urlsplit.
  • Preserves existing %XX escapes (no double-encoding of %20 or %2520), = in filenames, fsspec glob characters, query strings (e.g. presigned S3 query params), fragments, and all non-HTTP schemes (s3://, gs://, file://, and local filesystem paths with spaces).
  • Adds local-HTTP and unit regression tests in bioio_base/tests/test_io.py covering literal spaces, already-encoded %20, multiple spaces + Unicode, tabs/queries/fragments on https://, and local/file:// paths with spaces.

Tests:

  • New tests in bioio_base/tests/test_io.py: 3 fail / 2 control pass on main (d933a203); 5/5 pass with this fix.
  • Full offline bioio-base suite: 146 passed, 35 xfailed (0 regressions vs 141 passed, 35 xfailed on main).
  • End-to-end local-HTTP check with bioio-czi (aicspylibczi 4.0.1): literal-space CZI URLs now match %20 URLs and local files byte-for-byte on dims, pixels, and metadata.
  • Pinned ruff, ruff-format, and mypy pass on all touched files.

Found and written with AI agents; a separate AI referee reproduced the bug and verified the patch independently before this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

@BrianWhitneyAI BrianWhitneyAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @rpinho! Thanks for opening this. This fix totally works but I think its a little overcomplicated and outside of our normal style for bioio. I opened #91 as an alternative but let me know if I missed some of the nuance there.


import pathlib
from functools import partial
from http.server import HTTPServer, SimpleHTTPRequestHandler

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This testing method is a little unconventional for the bioio suite, not saying its wrong but Id like to do a little more reading on it before merging

@rpinho

rpinho commented Nov 26, 2026

Copy link
Copy Markdown
Author

Hey @BrianWhitneyAI,

Yeah, that makes sense — #91 looks much better and simpler. I think that's fine for %20, =, query params, and fragments. The only gotcha is uppercase HTTP:// or a non-ASCII host, and I mean, it probably works fine for most of the times.

Can close this out once #91 is merged. Thanks for getting this done!

This branch has not been deployed

No deployments
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 this pull request may close these issues.

2 participants