ssr: string redirectTo drops trailing slash in query and fragment
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #34512 của @alan-agius4 — đã merge
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 57/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- angular, typescript
Hướng nghiên cứu
Start with the two joins named in the issue: joinUrlParts in packages/angular/ssr/src/routes/ng-routes.ts and packages/angular/ssr/src/app.ts; compare how resolveRedirectTo handles query and fragment parts. Reproduce with the listed ng build and curl commands, including a base href and forwarded prefix. Done means string redirects preserve trailing slashes in query strings and fragments in the Location header.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Command
build, serve
Is this a regression?
- Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
none, same baseHref join is there since 19.0.0
Description
String redirectTo loses trailing / of query or fragment in Location: '/login?next=/a/' gives /login?next=/a and '/login#section/' gives /login#section. Same with X-Forwarded-Prefix and with base href /base/, on 22.2.4 and on main snapshot 22.3.0-next.3+sha-928169a
Function redirect with same target keeps it (/login?next=%2Fa%2F and /login#section/) since router serializes it, so same target gives diffrent Location depending only on how redirect is written
Minimal Reproduction
npx -p @angular/cli@latest ng new repro --ssr --defaults --skip-gitsrc/app/app.routes.ts:
import { Component } from '@angular/core';
import { Routes } from '@angular/router';
@Component({ template: 'login' })
class Login {}
export const routes: Routes = [
{ path: 'login', component: Login },
{ path: 'old', redirectTo: '/login?next=/a/' },
{ path: 'old-hash', redirectTo: '/login#section/' },
{ path: 'old-fn', redirectTo: () => '/login?next=/a/' },
{ path: 'old-fn-hash', redirectTo: () => '/login#section/' },
];
src/app/app.routes.server.ts:[{ path: '**', renderMode: RenderMode.Server }]so function redirects go through renderng buildthenNG_ALLOWED_HOSTS=localhost NG_TRUST_PROXY_HEADERS=x-forwarded-prefix node dist/repro/server/server.mjs- curl:
$ curl -si localhost:4000/old | grep -i '^location'
location: /login?next=/a
$ curl -si localhost:4000/old-hash | grep -i '^location'
location: /login#section
$ curl -si localhost:4000/old-fn | grep -i '^location'
location: /login?next=%2Fa%2F
$ curl -si localhost:4000/old-fn-hash | grep -i '^location'
location: /login#section/
$ curl -si -H 'X-Forwarded-Prefix: /app' localhost:4000/old | grep -i '^location'
location: /app/login?next=/a
$ curl -si -H 'X-Forwarded-Prefix: /app' localhost:4000/old-hash | grep -i '^location'
location: /app/login#section
With ng build --base-href /base/ it's /base/login?next=/a and /base/login#section. Slash is gone already at build time, dist/repro/server/angular-app-manifest.mjs has "redirectTo": "/login?next=/a"
Expected: /login?next=/a/ and /login#section/, with /app or /base in front when set
Actual: trailing slash of query and fragment is gone
Exception or Error
none, only Location header is wrong
Your Environment
Angular CLI : 22.2.4
Angular : 22.2.3
Node.js : 24.16.0
Package Manager : npm 11.13.0
Operating System : darwin arm64
┌───────────────────────────┬───────────────────┬───────────────────┐
│ Package │ Installed Version │ Requested Version │
├───────────────────────────┼───────────────────┼───────────────────┤
│ @angular/build │ 22.2.4 │ ^22.2.4 │
│ @angular/cli │ 22.2.4 │ ^22.2.4 │
│ @angular/common │ 22.2.3 │ ^22.2.0 │
│ @angular/compiler │ 22.2.3 │ ^22.2.0 │
│ @angular/compiler-cli │ 22.2.3 │ ^22.2.0 │
│ @angular/core │ 22.2.3 │ ^22.2.0 │
│ @angular/forms │ 22.2.3 │ ^22.2.0 │
│ @angular/platform-browser │ 22.2.3 │ ^22.2.0 │
│ @angular/platform-server │ 22.2.3 │ ^22.2.0 │
│ @angular/router │ 22.2.3 │ ^22.2.0 │
│ @angular/ssr │ 22.2.4 │ ^22.2.4 │
│ rxjs │ 7.8.2 │ ~7.8.0 │
│ typescript │ 6.0.3 │ ~6.0.2 │
│ vitest │ 5.0.5 │ ^5.0.0 │
└───────────────────────────┴───────────────────┴───────────────────┘
same output with @angular/ssr 22.3.0-next.3+sha-928169a from angular-ssr-builds
Anything else relevant?
joinUrlParts trims trailing / of every part, and two places still pass it whole target with query and fragment: joinUrlParts(baseHref, metadata.redirectTo) in extractRoutesAndCreateRouteTree and prefix join in AngularServerApp.handle
#34467 description says joinUrlParts is applied only to path portion when prepending baseHref or X-Forwarded-Prefix so trailing slashes in query or fragment are preserved, but both joins above still take whole target. If that's not intended I can send PR that splits off query and fragment first, like resolveRedirectTo does
- Ngôn ngữ chính
- TypeScript
- Star
- 27k
- Fork
- 11.8k
- Merge trung bình
- 1 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 241
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của angular/angular-cli
-
Can't use an array of hostnames in --allowedHosts cli parameter in @angular/build:dev-serverĐang mởarea: @angular/build gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
angular/angular-cli#33955 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/cli gemini-triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
angular/angular-cli#33055 · 1 bình luận · 3 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: @angular/build
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
angular/angular-cli#34524 · 2 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`ng generate app-shell` and `ng generate module --route` produce broken imports when a component `type` is configuredCó thể đã có người làm @MeAkib đã nhận 5 ngày trước. Đang mởarea: @schematics/angular
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
angular/angular-cli#34449 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Tailwind CSS v4 classes in new or moved files are not picked up by ng serve until another rebuildCó thể đã có người làm @MeAkib đã nhận 6 ngày trước. Đang mởarea: @angular/build
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
angular/angular-cli#34446 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của angular/angular-cli
Issue tương tự
-
Add: ON Phim Viet SDĐang mởcheck:passed streams:add
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Subagent progress token count ignores usage.iterations and swings on multi-iteration responsesĐang mởarea:agents area:cost bug platform:macos
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
anthropics/claude-code#105375 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
galaxyproject/loom#616 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
e2e-failure ready-to-code
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
redhat-developer/rhdh-plugin-export-overlays#4580 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày