Skip to content

fix(@angular/ssr): use router to normalize URLs for comparison#33057

Merged
alan-agius4 merged 2 commits intoangular:mainfrom
alan-agius4:encodings
Apr 28, 2026
Merged

fix(@angular/ssr): use router to normalize URLs for comparison#33057
alan-agius4 merged 2 commits intoangular:mainfrom
alan-agius4:encodings

Conversation

@alan-agius4
Copy link
Copy Markdown
Collaborator

Updates constructDecodedUrl in the SSR engine to use the Angular Router for parsing and serializing URLs instead of manual string manipulation and decoding.

This ensures that the URL comparison used to determine if a redirect is necessary is consistent with how the router interprets and serializes the URL. This prevents issues where differences in encoding or edge cases (like duplicate query parameters or empty values) could lead to incorrect comparison results and unexpected redirects.

Also updates tests to include edge cases for query parameters and paths to verify this behavior.

Fixes #33053

@alan-agius4 alan-agius4 requested a review from dgp1130 April 27, 2026 08:26
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Apr 27, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the URL construction logic in the Angular SSR utility to use the Router for parsing and serialization, ensuring consistency with the router's configuration. It also expands the test suite to cover complex and encoded URL scenarios. The feedback suggests renaming the constructDecodedUrl function to constructNormalizedUrl to accurately reflect its updated behavior of returning a serialized URL rather than a decoded one.

Comment thread packages/angular/ssr/src/utils/ng.ts
Comment thread packages/angular/ssr/src/utils/ng.ts
@alan-agius4 alan-agius4 linked an issue Apr 27, 2026 that may be closed by this pull request
Updates `constructDecodedUrl` in the SSR engine to use the Angular `Router` for parsing and serializing URLs instead of manual string manipulation and decoding.

This ensures that the URL comparison used to determine if a redirect is necessary is consistent with how the router interprets and serializes the URL. This prevents issues where differences in encoding or edge cases (like duplicate query parameters or empty values) could lead to incorrect comparison results and unexpected redirects.

Also updates tests to include edge cases for query parameters and paths to verify this behavior.

Fixes angular#33053
…oute tree

Updates the `getPathSegments` method in `RouteTree` to decode each path segment using `decodeURIComponent` after splitting the route by `/`.

This ensures that encoded characters in URL segments (such as spaces or encoded slashes) are correctly interpreted when matching incoming requests against the route tree. This prevents issues where encoded segments would fail to match their corresponding route definitions or wildcard patterns in the tree.

Also reverts experimental changes in `url.ts` and `router.ts` regarding matrix parameter handling, as the simple change in `route-tree.ts` is sufficient to resolve the issue and passes all tests.

Adds a test in `router_spec.ts` to verify that a URL with an encoded parameter containing spaces and slashes (`Bob%20%2F%20Roberts`) correctly matches a wildcard route (`/user/*`).

Fixes angular#33044
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 27, 2026
@alan-agius4 alan-agius4 merged commit 53b9623 into angular:main Apr 28, 2026
35 checks passed
@alan-agius4 alan-agius4 deleted the encodings branch April 28, 2026 07:00
@alan-agius4
Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/ssr target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SSR causes 302 redirects to normalized URL

3 participants