Skip to content

test: test: add null-byte escape test cases for '#' handling#473

Merged
alexander-akait merged 1 commit intowebpack:mainfrom
shayannab:test/hash-escape-docs
Feb 26, 2026
Merged

test: test: add null-byte escape test cases for '#' handling#473
alexander-akait merged 1 commit intowebpack:mainfrom
shayannab:test/hash-escape-docs

Conversation

@shayannab
Copy link
Contributor

Problem

When a project lives in a directory containing # (e.g. /home/user/f#/webpack),
webpack-dev-server fails to resolve modules because # is treated as a URL fragment
separator.

Ref: webpack/webpack#16819

Root Cause

The bug is not in parseIdentifier. The \0# null-byte escape is the designed
mechanism to embed a literal # in a filesystem path. The actual fix belongs
upstream in the code that constructs request strings from real filesystem paths so,
it must escape # as \0# before passing to the resolver.

Changes

Added test cases to test/identifier.test.js documenting the \0# escape mechanism:

  • \0# in path → unescaped to #, no fragment produced
  • \0# dir + real fragment at end
  • multiple \0# escapes + real fragment
  • \0# with both query and fragment
  • unescaped # still treated as fragment start (regression guard)
  • Windows paths with \0# escape

No production code was changed.

Test Results

All 653 tests pass ✅

Document the \0# escape mechanism in parseIdentifier — callers must
escape '#' in filesystem paths as '\0#' before passing to the resolver.
Unescaped '#' always starts a URL fragment.

Covers:
- \0# in path unescaped to '#' (no fragment produced)
- \0# dir + real fragment at end
- multiple \0# escapes, then a real fragment
- \0# with both query and fragment
- unescaped '#' still treated as fragment start (regression guard)
- Windows paths with \0# null-byte escape

Ref: webpack/webpack#16819
@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.41%. Comparing base (39d56d3) to head (7e16d32).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #473   +/-   ##
=======================================
  Coverage   93.41%   93.41%           
=======================================
  Files          49       49           
  Lines        2384     2384           
  Branches      717      717           
=======================================
  Hits         2227     2227           
  Misses        128      128           
  Partials       29       29           
Flag Coverage Δ
integration 93.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alexander-akait alexander-akait merged commit 5cb58ca into webpack:main Feb 26, 2026
28 checks passed
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