Fix Windows filename/path handling (reserved names, node probe, file URLs)#13622
Draft
abidlabs wants to merge 3 commits into
Draft
Fix Windows filename/path handling (reserved names, node probe, file URLs)#13622abidlabs wants to merge 3 commits into
abidlabs wants to merge 3 commits into
Conversation
…nd preview Prefix reserved DOS device names in strip_invalid_filename_characters, silence where/which node stderr, and use proper file:// URLs for Windows paths. Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
🪼 branch checks and previews
Install Gradio from this PR pip install https://huggingface.co/buckets/gradio/pypi-previews/resolve/5a2ac73e99eb124ad219518c39aa32dbd90ecfb0/gradio-6.20.0-py3-none-any.whlInstall Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@5a2ac73e99eb124ad219518c39aa32dbd90ecfb0#subdirectory=client/python"Import Gradio JS Client from this PR via CDN import { Client } from "https://huggingface.co/buckets/gradio/npm-previews/resolve/5a2ac73e99eb124ad219518c39aa32dbd90ecfb0/browser.js"; |
Collaborator
🦄 change detectedThis Pull Request includes changes to the following packages.
|
Babylon.js can reject after the file-level afterAll removed the listener, causing flaky js-test failures. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens several Windows-specific path and filename edge cases across Gradio’s Python backend, Python client utilities, and the custom component preview/build tooling to avoid invalid filesystem paths, noisy probes, and malformed file:// URLs.
Changes:
- Sanitize Windows reserved device names in
strip_invalid_filename_characters()so uploads likeCON.txtdon’t fail on NTFS. - Suppress stderr when probing for
nodeviawhere/whichto prevent Windows “INFO: Could not find files…” noise. - Generate valid
file://URLs on Windows by usingpathToFileURL(...).href(JS) andPath.as_uri()(Python).
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
js/preview/src/dev.ts |
Switch dynamic import of gradio.config.js to pathToFileURL(...).href for valid file URLs on Windows. |
js/preview/src/build.ts |
Same pathToFileURL(...).href fix during preview build-time config import. |
js/model3D/Model3D.test.ts |
Adjust unhandled rejection suppression message extraction; removes global listener cleanup (needs fix). |
gradio/utils.py |
Silence stderr for where/which node probing to avoid Windows console noise. |
gradio/node_server.py |
Use Path.as_uri() for Windows --import file URLs to avoid invalid drive-path URLs. |
client/python/test/test_utils.py |
Add tests covering Windows reserved device name sanitization. |
client/python/gradio_client/utils.py |
Implement reserved-device-name prefixing in strip_invalid_filename_characters(). |
.changeset/rude-forks-agree.md |
Add Changeset entry for the patch release(s). |
Comments suppressed due to low confidence (1)
gradio/utils.py:1847
- The Windows
where nodeprobe can raiseFileNotFoundErrorifwhereis unavailable (e.g. non-standard Windows environments). The Unix branch already guards this; the Windows branch should catch it too to avoid crashing while probing for Node.
try:
# On Windows, try using 'where' command. Suppress stderr so a missing
# node does not print "INFO: Could not find files for the given pattern(s)."
if sys.platform == "win32":
windows_path = (
subprocess.check_output(["where", "node"], stderr=subprocess.DEVNULL)
.decode()
.strip()
.split("\r\n")[0]
)
if os.path.exists(windows_path):
return windows_path
except subprocess.CalledProcessError:
# Command failed, fall back to checking common install locations
pass
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
43
to
47
| beforeAll(() => { | ||
| window.addEventListener("unhandledrejection", suppress_3d_library_errors); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| window.removeEventListener("unhandledrejection", suppress_3d_library_errors); | ||
| }); | ||
|
|
||
| const base_props = { |
| "gradio_client": patch | ||
| --- | ||
|
|
||
| fix:Fix Windows filename/path handling (reserved names, node probe, file URLs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Hardens a few related Windows path/filename issues:
CON,PRN,AUX,NUL,COM1–COM9,LPT1–LPT9) instrip_invalid_filename_charactersso uploads likeCON.txtremain valid filesystem paths on NTFS. Follows maintainer guidance to skip a global extension blacklist and keep this as a targeted sanitizer fix.stderr=subprocess.DEVNULLwhen probing fornodeviawhere/whichso missing Node does not leakINFO: Could not find files for the given pattern(s).on Windows.pathToFileURL(...).href(andPath.as_uri()in the SSR node server) instead of"file://" + path, which produces invalid URLs for Windows drive paths.Closes: #13443
Closes: #9974
Closes: #8781
AI Disclosure
Testing and Formatting Your Code
Verification:
Minimal demo (not committed —
demo_issue_13443.py):Expected:
CON.txt→_CON.txt,console.logunchanged.Made with Cursor