Skip to content

Commit 998c720

Browse files
alan-agius4clydin
authored andcommitted
fix(@angular-devkit/build-angular): decode URL pathname decoding during SSG fetch
Previously, missing URL decoding led to assets not being located correctly. Closes: #27590 (cherry picked from commit 5f14787)
1 parent 1ab1c6c commit 998c720

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/angular_devkit/build_angular/src/utils/server-rendering/fetch-patch.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ export function patchFetchToLoadInMemoryAssets(): void {
3939
return originalFetch(input, init);
4040
}
4141

42-
const { pathname, protocol } = url;
42+
const { protocol } = url;
43+
const pathname = decodeURIComponent(url.pathname);
4344

4445
if (protocol !== RESOLVE_PROTOCOL || !assetFiles[pathname]) {
4546
// Only handle relative requests or files that are in assets.

tests/legacy-cli/e2e/tests/build/prerender/http-requests-assets.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ export default async function () {
3838
],
3939
};
4040
`,
41+
4142
// Add asset
4243
'src/assets/media.json': JSON.stringify({ dataFromAssets: true }),
44+
'src/assets/media with-space.json': JSON.stringify({ dataFromAssetsWithSpace: true }),
45+
4346
// Update component to do an HTTP call to asset.
4447
'src/app/app.component.ts': `
4548
import { Component, inject } from '@angular/core';
@@ -53,16 +56,23 @@ export default async function () {
5356
imports: [CommonModule, RouterOutlet],
5457
template: \`
5558
<p>{{ data | json }}</p>
59+
<p>{{ dataWithSpace | json }}</p>
5660
<router-outlet></router-outlet>
5761
\`,
5862
})
5963
export class AppComponent {
6064
data: any;
65+
dataWithSpace: any;
66+
6167
constructor() {
6268
const http = inject(HttpClient);
6369
http.get('/assets/media.json').subscribe((d) => {
6470
this.data = d;
6571
});
72+
73+
http.get('/assets/media%20with-space.json').subscribe((d) => {
74+
this.dataWithSpace = d;
75+
});
6676
}
6777
}
6878
`,
@@ -74,4 +84,8 @@ export default async function () {
7484
'dist/test-project/browser/index.html',
7585
/<p>{[\S\s]*"dataFromAssets":[\s\S]*true[\S\s]*}<\/p>/,
7686
);
87+
await expectFileToMatch(
88+
'dist/test-project/browser/index.html',
89+
/<p>{[\S\s]*"dataFromAssetsWithSpace":[\s\S]*true[\S\s]*}<\/p>/,
90+
);
7791
}

0 commit comments

Comments
 (0)