fix(common): only strip a literal /index.html suffix in AngularJSUrlCodec#69023
Open
fg0x0 wants to merge 1 commit into
Open
fix(common): only strip a literal /index.html suffix in AngularJSUrlCodec#69023fg0x0 wants to merge 1 commit into
fg0x0 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
JeanMeche
approved these changes
May 30, 2026
Member
|
Your commit has 3 authors with 2 that haven't signed the CLA. Can you amend your commit and remove the unnecessary authors. Without this we can't accept this PR. Thank you for your understanding. |
c6396fe to
e017869
Compare
…odec Sibling miss of the fix in `Location._stripIndexHtml` (commit d109bf9). `AngularJSUrlCodec._stripIndexHtml` in `@angular/common/upgrade` has the identical regex with an unescaped `.`, so it strips arbitrary single characters between `index` and `html`. For example `encodePath` collapses `/page/indexXhtml` and `/page/index_html` to `/page`, and `areEqual` (used by `$locationShim` to detect URL changes) treats those URLs as equal to `/page`, suppressing legitimate URL-change events in hybrid AngularJS-Angular apps. Escape the dot so only the literal `/index.html` suffix is stripped, matching the precedent set by `Location._stripIndexHtml`.
e017869 to
e1cae21
Compare
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.
PR Checklist
What is the current behavior?
AngularJSUrlCodec._stripIndexHtmlin@angular/common/upgrade(packages/common/upgrade/src/params.ts:238) has an unescaped.in the strip regex/\/index.html$/. The unescaped dot matches any character, so suffixes such as/indexXhtml,/index_html,/index!html, and/index/htmlare all stripped to the empty string instead of being preserved.This is the same bug class that was fixed by commit d109bf9 ("fix(common): only strip a literal /index.html suffix from URLs") in
Location._stripIndexHtml(packages/common/src/location/location.ts:319), but the sibling copy in the upgrade package'sAngularJSUrlCodecwas not updated.Repro (Node only, mirrors the buggy regex):
```js
function buggy(url) { return url.replace(//index.html$/, ""); }
function fixed(url) { return url.replace(//index.html$/, ""); }
console.log(buggy("/page/indexXhtml")); // "/page" <- bug
console.log(fixed("/page/indexXhtml")); // "/page/indexXhtml" <- intended
```
In hybrid AngularJS-Angular apps that wire up
LocationUpgradeModule, this affects$location.path()/$location.url()(route resolves to the stripped URL instead of the literal one) and$location.replacechange detection inlocation_shim.ts:198, which callsurlCodec.areEqual(oldUrl, newUrl).areEqual('/page', '/page/indexXhtml')returnstrueand the URL-change event is suppressed.Issue Number: N/A
What is the new behavior?
Escape the dot so the regex only matches the literal
/index.htmlsuffix, matching the precedent set byLocation._stripIndexHtml.Does this PR introduce a breaking change?
AngularJSUrlCodec.encodePathnow preserves trailing segments that happen to match/index<any>html(e.g./indexXhtml,/index_html). Apps that intentionally relied on the lossy stripping to alias arbitraryindex<x>htmlsuffixes to the parent path were depending on a regex typo and are extremely unlikely to exist; the parallelLocation._stripIndexHtmlshipped this same change in d109bf9 without being flagged as breaking.Other information
Tests added in
packages/common/upgrade/test/params.spec.tsmirror the cases used in d109bf9'slocation_spec.tsaddition.