Skip to content

fix(platform-server): correctly handle absolute relative URLs#37341

Closed
CaerusKaru wants to merge 1 commit into
angular:masterfrom
CaerusKaru:abs
Closed

fix(platform-server): correctly handle absolute relative URLs#37341
CaerusKaru wants to merge 1 commit into
angular:masterfrom
CaerusKaru:abs

Conversation

@CaerusKaru

Copy link
Copy Markdown
Member

Previously, we would simply prepend any relative URL with the HREF
for the current route (pulled from document.location). However,
this does not correctly account for the leading slash URLs that
would otherwise be parsed correctly in the browser, or the
presence of a base HREF in the DOM.

Therefore, we use the built-in URL implementation for NodeJS,
which implements the WHATWG standard that's used in the browser.
We also pull the base HREF from the DOM, falling back on the full
HREF as the browser would, to form the correct request URL.

Fixes #37314

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: 37314

What is the new behavior?

Add support for base HREF and absolute relative URLs on SSR HTTP requests.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Comment thread packages/platform-server/src/http.ts Outdated

@alan-agius4 alan-agius4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one small nit.

Comment thread packages/platform-server/src/http.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this regex also doesn't cover //foo.com/bar URLs, which are absolute paths. I suspect they might work by accident, as they'll be treated as "rooted" by the first /.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CaerusKaru can you do a followup PR for this please?

@alxhub

alxhub commented Jun 1, 2020

Copy link
Copy Markdown
Member

Presubmit

@matsko matsko added the area: core Issues related to the framework runtime label Jun 3, 2020
@ngbot ngbot Bot added this to the needsTriage milestone Jun 3, 2020
Previously, we would simply prepend any relative URL with the HREF
for the current route (pulled from document.location). However,
this does not correctly account for the leading slash URLs that
would otherwise be parsed correctly in the browser, or the
presence of a base HREF in the DOM.

Therefore, we use the built-in URL implementation for NodeJS,
which implements the WHATWG standard that's used in the browser.
We also pull the base HREF from the DOM, falling back on the full
HREF as the browser would, to form the correct request URL.

Fixes angular#37314
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release area: server Issues related to server-side rendering action: presubmit The PR is in need of a google3 presubmit and removed area: core Issues related to the framework runtime action: merge The PR is ready for merge by the caretaker labels Jun 5, 2020
@kyliau kyliau removed the action: presubmit The PR is in need of a google3 presubmit label Jun 8, 2020
@atscott atscott closed this in 7301e70 Jun 9, 2020
atscott pushed a commit that referenced this pull request Jun 9, 2020
Previously, we would simply prepend any relative URL with the HREF
for the current route (pulled from document.location). However,
this does not correctly account for the leading slash URLs that
would otherwise be parsed correctly in the browser, or the
presence of a base HREF in the DOM.

Therefore, we use the built-in URL implementation for NodeJS,
which implements the WHATWG standard that's used in the browser.
We also pull the base HREF from the DOM, falling back on the full
HREF as the browser would, to form the correct request URL.

Fixes #37314

PR Close #37341
CaerusKaru added a commit to CaerusKaru/angular that referenced this pull request Jun 12, 2020
mhevery pushed a commit that referenced this pull request Jun 12, 2020
ngwattcos pushed a commit to ngwattcos/angular that referenced this pull request Jun 25, 2020
…r#37341)

Previously, we would simply prepend any relative URL with the HREF
for the current route (pulled from document.location). However,
this does not correctly account for the leading slash URLs that
would otherwise be parsed correctly in the browser, or the
presence of a base HREF in the DOM.

Therefore, we use the built-in URL implementation for NodeJS,
which implements the WHATWG standard that's used in the browser.
We also pull the base HREF from the DOM, falling back on the full
HREF as the browser would, to form the correct request URL.

Fixes angular#37314

PR Close angular#37341
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 10, 2020
profanis pushed a commit to profanis/angular that referenced this pull request Sep 5, 2020
…r#37341)

Previously, we would simply prepend any relative URL with the HREF
for the current route (pulled from document.location). However,
this does not correctly account for the leading slash URLs that
would otherwise be parsed correctly in the browser, or the
presence of a base HREF in the DOM.

Therefore, we use the built-in URL implementation for NodeJS,
which implements the WHATWG standard that's used in the browser.
We also pull the base HREF from the DOM, falling back on the full
HREF as the browser would, to form the correct request URL.

Fixes angular#37314

PR Close angular#37341
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: server Issues related to server-side rendering cla: yes target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

platform-server - Changes introduced in 10.0.0-next.8 to convert relative URLs to absolute URLs breaks SSR

6 participants