Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions apps/web/lib/api/links/case-sensitivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,32 @@ export const encodeKey = (text: string): string => {
)
.join("");

return Buffer.from(xored).toString("base64");
// Use hex encoding instead of base64 to avoid case-sensitivity collisions
// Hex is case-insensitive, so we normalize to lowercase for consistency
// Prefix with "h:" to distinguish from old base64 format (":" is not in base64 alphabet)
const hexEncoded = Buffer.from(xored).toString("hex").toLowerCase();
return `h:${hexEncoded}`;
};

export const decodeKey = (hash: string): string => {
if (!hash) return "";

const xored = Buffer.from(hash, "base64").toString();
let xored: string;

// Backwards compatibility: detect format by prefix
// New format: "h:" prefix (case-insensitive) indicates hex encoding
// Old format: no prefix, base64 encoding
// Normalize prefix check to handle case-insensitive databases
const normalizedHash = hash.toLowerCase();
if (normalizedHash.startsWith("h:")) {
// New hex format - remove prefix and decode as hex
// Normalize to lowercase to handle case-insensitive database storage
const hexPart = normalizedHash.slice(2);
xored = Buffer.from(hexPart, "hex").toString("utf8");
} else {
// Old base64 format - decode as base64
xored = Buffer.from(hash, "base64").toString("utf8");
}

return xored
.split("")
Expand Down
2 changes: 2 additions & 0 deletions apps/web/tests/redirects/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe.runIf(env.CI)("Link Redirects", async () => {
const h = new IntegrationHarness();

test("root", async () => {
console.log({baseUrl: h.baseUrl})
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Remove debug console.log statement.

This console.log appears to be a debug artifact that should be removed before merging. It clutters test output without providing value in the production test suite.

🧹 Proposed fix
   test("root", async () => {
-    console.log({baseUrl: h.baseUrl})
-
     const response = await fetch(h.baseUrl, fetchOptions);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
console.log({baseUrl: h.baseUrl})
test("root", async () => {
const response = await fetch(h.baseUrl, fetchOptions);
🤖 Prompt for AI Agents
In @apps/web/tests/redirects/index.test.ts at line 19, Remove the debug
console.log({baseUrl: h.baseUrl}) line from the test (index.test.ts): delete
that console.log call that references h.baseUrl so the test output is clean,
then run the test suite to confirm no residual debug logging remains.


const response = await fetch(h.baseUrl, fetchOptions);

// the location should start with "https://dub.co"
Expand Down
Loading