angular / angular

Deliver web apps with confidence 🚀
https://angular.dev
MIT License
94.71k stars 24.68k forks source link

URL containing space fails to be fetched during prerender phase #55655

Closed lukasmatta closed 2 weeks ago

lukasmatta commented 2 weeks ago

Which @angular/* package(s) are the source of the bug?

Don't known / other

Is this a regression?

No

Description

When there is a URL containing space being fetched, it fails during prerendering. Encoding space to be %20 doesn't help. I've tried it with both withFetch() and without it when providing HttpClient.

How to reproduce: Clone https://github.com/lukasmatta/prerenderingproblem Run npm install then run npm build

Please provide a link to a minimal reproduction of the bug

https://github.com/lukasmatta/prerenderingproblem

Please provide the exception or error you saw

ERROR TypeError: Failed to parse URL from /assets/Folder%20space/test.txt
    at node:internal/deps/undici/undici:12618:11
    at a.invoke (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:6639)
    at Object.onInvoke (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/chunk-I5RKM5LS.mjs:34:17372)
    at a.invoke (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:6579)
    at p.run (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:1965)
    at file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:4:577
    at a.invokeTask (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:7265)
    at Object.onInvokeTask (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/chunk-I5RKM5LS.mjs:34:17188)
    at a.invokeTask (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:7186)
    at p.runTask (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:2577) {
  [cause]: TypeError [ERR_INVALID_URL]: Invalid URL
      at new NodeError (node:internal/errors:405:5)
      at new URL (node:internal/url:676:13)
      at new Request (node:internal/deps/undici/undici:6108:25)
      at fetch (node:internal/deps/undici/undici:10396:25)
      at Object.fetch (node:internal/deps/undici/undici:12617:10)
      at fetch (node:internal/process/pre_execution:281:25)
      at patchedFetch (//PrerenderSpaceUrl/node_modules/@angular-devkit/build-angular/src/utils/server-rendering/fetch-patch.js:42:20)
      at file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:4:3273
      at l.<computed> (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/polyfills.server.mjs:3:12973)
      at e.<anonymous> (file:////PrerenderSpaceUrl/.angular/prerender-root/2bfae38a-22b4-47d1-9c2c-0681f0ed977a/chunk-I5RKM5LS.mjs:35:13916) {
    input: '/assets/Folder%20space/test.txt',
    code: 'ERR_INVALID_URL'
  }
}

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.6
Node: 18.20.1
Package Manager: npm 10.5.0
OS: darwin arm64

Angular: 17.3.7
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.6
@angular-devkit/build-angular   17.3.6
@angular-devkit/core            17.3.6
@angular-devkit/schematics      17.3.6
@angular/cli                    17.3.6
@angular/ssr                    17.3.6
@schematics/angular             17.3.6
rxjs                            7.8.1
typescript                      5.4.5
zone.js                         0.14.5

Anything else?

No response

lukasmatta commented 2 weeks ago

Transfered to angular-cli https://github.com/angular/angular-cli/issues/27590