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

Fix shortlink resolution bug #1044

Merged
merged 4 commits into from
Mar 18, 2024
Merged

Fix shortlink resolution bug #1044

merged 4 commits into from
Mar 18, 2024

Conversation

EthanThatOneKid
Copy link
Owner

@EthanThatOneKid EthanThatOneKid commented Mar 16, 2024

Previously

The shortlink resolver wasn't working correctly. It would try to match invalid paths to shortlinks.

Now

The shortlink resolver is fixed! It correctly identifies shortlinks by looking at each segment (part separated by "/") within the path, from the beginning to the end of the string. So, now searching for "/colors" will find the correct shortlink instead of resolving incorrectly to "/c".

src/lib/server/links/resolve.ts

    let id = pathname.slice(1) as ID;
    while (id.length > 0 && !shortlinks[id]) {
-      id = id.slice(0, id.lastIndexOf('/')) as ID;
+      const slashIndex = id.lastIndexOf('/');
+      if (slashIndex === -1) {
+        break;
+      }
+
+      id = id.slice(0, slashIndex) as ID;
    }

    if (!shortlinks[id]) {

Copy link

netlify bot commented Mar 16, 2024

Deploy Preview for acmcsuf ready!

Name Link
🔨 Latest commit edb6010
🔍 Latest deploy log https://app.netlify.com/sites/acmcsuf/deploys/65f76b98661ecb00083285ba
😎 Deploy Preview https://deploy-preview-1044--acmcsuf.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@EthanThatOneKid EthanThatOneKid marked this pull request as ready for review March 16, 2024 20:24
@EthanThatOneKid EthanThatOneKid linked an issue Mar 16, 2024 that may be closed by this pull request
Copy link
Collaborator

@karnikaavelumani karnikaavelumani left a comment

Choose a reason for hiding this comment

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

Thank you for this PR! LGTM!

Copy link
Owner Author

@EthanThatOneKid EthanThatOneKid left a comment

Choose a reason for hiding this comment

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

The specific test cases listed in #1019 (comment) are confirmed to be working as expected.

@EthanThatOneKid EthanThatOneKid merged commit ecc7720 into main Mar 18, 2024
8 checks passed
@EthanThatOneKid EthanThatOneKid deleted the fix/1019 branch March 18, 2024 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dev-* links are broken
2 participants