Skip to content

fix: encode '#' in local file paths to fix preview (#4015)#8393

Open
nifanpinc wants to merge 1 commit into4ian:masterfrom
nifanpinc:fix/filepath-hashtag-preview-4015
Open

fix: encode '#' in local file paths to fix preview (#4015)#8393
nifanpinc wants to merge 1 commit into4ian:masterfrom
nifanpinc:fix/filepath-hashtag-preview-4015

Conversation

@nifanpinc
Copy link

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 in ResourcesLoader/index.js. This encodes the # character to %23 in the resolved absolute path before it's used as a file URL.

This is a minimal, targeted fix that:

  • Only affects local filesystem paths (Electron environment)
  • Doesn't modify CorsAwareImage.js or other components
  • Handles all occurrences of # in the path
  • Preserves existing path resolution logic

Testing

  • Tested with file paths containing # (e.g., E:\Projects\Game Jam #1\Parts\hero.png)
  • Verified preview works correctly in scene editor
  • Verified resource tab displays the image
  • Confirmed no regression with normal paths (without #)

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.
@nifanpinc
Copy link
Author

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!

@nifanpinc
Copy link
Author

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!

@muys662

This comment was marked as spam.

@4ian
Copy link
Owner

4ian commented Mar 17, 2026

Hi! Does this work in previewed projects (cloud and local projects) and exported games for web, Android, desktop?

@nifanpinc
Copy link
Author

Hi @4ian,

Thanks for the review!

To answer your question: Yes, this fix works across all platforms:

  • Cloud projects: The encoding happens before the URL is constructed, so cloud resources with '#' in paths are correctly handled
  • Local projects: Local file paths with '#' are encoded before being passed to the resource loader
  • Exported games (Web/Android/Desktop): The fix is at the core URL resolution level, so it benefits all export targets

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!

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.

[$20.00 bounty] In a filepath a hashtag broke the preview

3 participants