EthanThatOneKid / acmcsuf.com

🐘 Official website of CSUF's ACM chapter
https://acmcsuf.com
MIT License
36 stars 45 forks source link

Fix shortlink resolution bug #1044

Closed EthanThatOneKid closed 3 months ago

EthanThatOneKid commented 3 months ago

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]) {
netlify[bot] commented 3 months ago

Deploy Preview for acmcsuf ready!

Name Link
Latest commit edb6010db7ba925b049c05ffc55ecb30c230c4e7
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.