Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): decode URL pathname decoding duri…
Browse files Browse the repository at this point in the history
…ng SSG fetch

Previously, missing URL decoding led to assets not being located correctly.

Closes: angular#27590
(cherry picked from commit 5f14787)
  • Loading branch information
alan-agius4 committed May 3, 2024
1 parent c6b82f6 commit e2d2e86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export function patchFetchToLoadInMemoryAssets(): void {
return originalFetch(input, init);
}

const { pathname, protocol } = url;
const { protocol } = url;
const pathname = decodeURIComponent(url.pathname);

if (protocol !== RESOLVE_PROTOCOL || !assetFiles[pathname]) {
// Only handle relative requests or files that are in assets.
Expand Down
14 changes: 14 additions & 0 deletions tests/legacy-cli/e2e/tests/build/prerender/http-requests-assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ export default async function () {
],
};
`,

// Add asset
'src/assets/media.json': JSON.stringify({ dataFromAssets: true }),
'src/assets/media with-space.json': JSON.stringify({ dataFromAssetsWithSpace: true }),

// Update component to do an HTTP call to asset.
'src/app/app.component.ts': `
import { Component, inject } from '@angular/core';
Expand All @@ -53,16 +56,23 @@ export default async function () {
imports: [CommonModule, RouterOutlet],
template: \`
<p>{{ data | json }}</p>
<p>{{ dataWithSpace | json }}</p>
<router-outlet></router-outlet>
\`,
})
export class AppComponent {
data: any;
dataWithSpace: any;
constructor() {
const http = inject(HttpClient);
http.get('/assets/media.json').subscribe((d) => {
this.data = d;
});
http.get('/media%20with-space.json').subscribe((d) => {
this.dataWithSpace = d;
});
}
}
`,
Expand All @@ -74,4 +84,8 @@ export default async function () {
'dist/test-project/browser/index.html',
/<p>{[\S\s]*"dataFromAssets":[\s\S]*true[\S\s]*}<\/p>/,
);
await expectFileToMatch(
'dist/test-project/browser/index.html',
/<p>{[\S\s]*"dataFromAssetsWithSpace":[\s\S]*true[\S\s]*}<\/p>/,
);
}

0 comments on commit e2d2e86

Please sign in to comment.