Skip to content
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

breaking: fix path resolution #11276

Merged
merged 2 commits into from
Dec 13, 2023
Merged

breaking: fix path resolution #11276

merged 2 commits into from
Dec 13, 2023

Conversation

Rich-Harris
Copy link
Member

Our resolve utility was returning incorrect results in the case where path was just a . character, leading to confusion such as #11273 (comment).

This implementation delegates to new URL(...), so it's more or less guaranteed to be correct whatever edge cases we throw at it

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Dec 12, 2023

🦋 Changeset detected

Latest commit: 70f0e20

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

What were the implications of this buggy behavior? Was it resulting in a bug in some way?

if (path[0] === '#') return base + path;
if (path === '') return base;
// special case
if (path[0] === '/' && path[1] === '/') return path;
Copy link
Member

Choose a reason for hiding this comment

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

what's this special case about? Is this some extra thing we need to mention in the docs? What does this mean for ''?

Copy link
Member Author

Choose a reason for hiding this comment

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

protocol-relative URLs should remain protocol-relative, but the new URL(...) technique means we lose that information. so we need to special-case it

"/test♥hex"
"/test%22quotation",
"/test%E2%99%A1decimal",
"/test%E2%99%A5hex"
Copy link
Member

Choose a reason for hiding this comment

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

The previous results had the character references persisted - will this somehow affect other stuff negatively / in a breaking way now that they no longer are?

Copy link
Member Author

Choose a reason for hiding this comment

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

I figured if it did, tests would start failing. Seems fine. Though we're probably now double-decoding at prerender time

Copy link
Member

Choose a reason for hiding this comment

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

Oof. Double-decoding is bad and would result in breakages. Maybe we don't have a test for prerendering an encoded URL?

Copy link
Member Author

Choose a reason for hiding this comment

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

We do:

If there's a bug, it's very well-hidden, and we can fix it when it reveals itself. It shouldn't block merging

@Rich-Harris
Copy link
Member Author

Was it resulting in a bug in some way?

Yes #11273 (comment)

@benmccann benmccann added this to the 2.0 milestone Dec 12, 2023
@dummdidumm
Copy link
Member

I mean, yes, this is a bug that showed itself there, but I don't understand yet what actual issue this would cause. Maybe the current behavior is actually more desireable?

@Rich-Harris
Copy link
Member Author

It doesn't matter if it's more desirable, it's incorrect!

@dummdidumm
Copy link
Member

That's like saying measuring in inches is incorrect (obviously is, wtf America) and using centimeters is the better variant, but if it turns out that it works in practise and noone has an issue with it, why change it?

@Rich-Harris
Copy link
Member Author

Because it's stupidly confusing if we resolve URLs differently to everyone else on the planet. The fact that it makes it marginally easier to do something you almost certainly don't want to do (emulating confusing default cookie path behaviour) is a terrible reason to keep the broken behaviour

@dummdidumm
Copy link
Member

Ok fine. I just really wished we would've found some special string to signal "I want the default browser behavior" 😄

@Rich-Harris Rich-Harris merged commit 04fecb7 into version-2 Dec 13, 2023
13 checks passed
@Rich-Harris Rich-Harris deleted the fix-url-resolution branch December 13, 2023 14:52
@github-actions github-actions bot mentioned this pull request Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants