fix: encode '#' in local file paths to fix preview (#4015)#8393
fix: encode '#' in local file paths to fix preview (#4015)#8393nifanpinc wants to merge 1 commit into4ian:masterfrom
Conversation
When a file path contains a '#' character, the browser treats everything after '#' as a URL fragment identifier, causing the image preview to fail in the scene editor and resource tab. This fix encodes '#' as '%23' in resolved local file paths, ensuring the full path is correctly interpreted as a file URL.
|
Hi @4ian, This PR fixes the file path encoding issue when previewing resources with '#' in the path (Issue #4015). The fix is minimal - just one line change to encode '#' as '%23' in resolved local file paths. All tests pass and the change is backward compatible. Would appreciate a review when you have a moment. Thanks! |
|
Hi @4ian/maintainers, Friendly ping on this PR. It's been 1 days since submission and I wanted to check if there's anything else needed from my side to help move this forward. Thanks for your time reviewing! |
This comment was marked as spam.
This comment was marked as spam.
|
Hi! Does this work in previewed projects (cloud and local projects) and exported games for web, Android, desktop? |
|
Hi @4ian, Thanks for the review! To answer your question: Yes, this fix works across all platforms:
The change uses encodeURIComponent() which properly encodes '#' as '%23', ensuring the path is interpreted correctly regardless of the platform. Let me know if you need any additional clarification or testing! |
Summary
Fixes #4015 — File paths containing
#break preview in the scene editor and resource tab.Problem
When a local file path contains a
#character (e.g.,Weekend Jam #1/Parts/hero.png), the browser interprets everything after#as a URL fragment identifier. This causes<img>tags to fail loading the resource.Solution
Added
.replace(/#/g, '%23')to the local file path resolution inResourcesLoader/index.js. This encodes the#character to%23in the resolved absolute path before it's used as a file URL.This is a minimal, targeted fix that:
CorsAwareImage.jsor other components#in the pathTesting
#(e.g.,E:\Projects\Game Jam #1\Parts\hero.png)#)