Skip to content

fix(@angular/build): decode URL pathname decoding during SSG fetch #27592

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
'public/media.json': JSON.stringify({ dataFromAssets: true }),
'public/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('/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>/,
);
}