Skip to content

Adds support for malformed channel URLs (thx grok)#3412

Merged
tzarebczan merged 1 commit intomasterfrom
fix-bad-grok-urls
Feb 6, 2026
Merged

Adds support for malformed channel URLs (thx grok)#3412
tzarebczan merged 1 commit intomasterfrom
fix-bad-grok-urls

Conversation

@tzarebczan
Copy link
Contributor

@tzarebczan tzarebczan commented Feb 4, 2026

Addresses an issue where channel URLs from platforms like Grok/Twitter may omit the "@" prefix.

Implements logic to detect and correct these malformed URLs, ensuring correct resolution and redirection.

This improves the user experience by handling cases where users encounter broken links due to missing "@" symbols in channel URLs.

Fixes

Issue Number:

What is the current behavior?

What is the new behavior?

Other information

PR Checklist

Toggle...

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting)
  • Refactoring (no functional changes)
  • Documentation changes
  • Other - Please describe:

Please check all that apply to this PR using "x":

  • I have checked that this PR is not a duplicate of an existing PR (open, closed or merged)
  • I have checked that this PR does not introduce a breaking change
  • This PR introduces breaking changes and I have provided a detailed explanation below

Summary by CodeRabbit

Release Notes

  • New Features
    • Added automatic detection and correction of malformed channel URLs with missing channel prefixes.
    • Malformed URLs are now automatically redirected to the corrected path while preserving query parameters and hash segments.
    • Correction flow applied consistently across web pages, API endpoints, and client-side rendering.

@coderabbitai
Copy link

coderabbitai bot commented Feb 4, 2026

📝 Walkthrough

Walkthrough

This PR introduces a channel path correction system that detects malformed LBRY channel URLs missing the @ prefix and automatically redirects to corrected paths. The feature includes server-side correction during HTML generation and request handling, plus client-side correction with redirect during claim rendering.

Changes

Cohort / File(s) Summary
Channel Path Correction Utilities
web/src/lbryURI.js
Added two new public utility functions: getCorrectedChannelUri() for lbry:// URIs and getCorrectedChannelWebPath() for web paths. Both detect missing @ channel prefixes, validate patterns, and return corrected paths or null.
Server-Side Correction Integration
web/src/html.js, web/src/oEmbed.js, web/src/routes.js
Integrated path correction checks into server-side processing. html.js extracts and corrects paths before URI parsing. oEmbed.js applies correction when resolving claims from URLs. routes.js guards against overwriting redirect status with HTML content.
Client-Side Correction
ui/hocs/withResolvedClaimRender/view.jsx
Computes corrected path from current location pathname and triggers client-side redirect via history.replace() with loading state. Integrated into claim rendering component lifecycle.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A rabbit hops through channels bright,
Detecting paths that don't look right.
@-symbols missing? Not for long!
Corrections bloom, and reroute is strong.
Server and client, hand in hand,
Build the corrected LBRY land. ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding support for malformed channel URLs. It directly corresponds to the primary objective of detecting and correcting URLs missing the '@' prefix.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-bad-grok-urls

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@web/src/html.js`:
- Line 24: In the resolveClaimOrRedirect function locate the branch that handles
a corrected URL (where getCorrectedChannelUri/normalizeClaimUrl is used) and
change it so the redirect is conditional: if ignoreRedirect is true return the
resolved claim/claim object (no redirect) otherwise perform the existing
redirect behavior; ensure you reference resolveClaimOrRedirect and
getCorrectedChannelUri (and normalizeClaimUrl if used) when making the change
and apply the same guard to the other corrected-URL branch around lines 496-507.

web/src/html.js Outdated
const { lbryProxy: Lbry } = require('../lbry');
const { getHomepageJsonV1 } = require('./getHomepageJSON');
const { buildURI, parseURI, normalizeClaimUrl } = require('./lbryURI');
const { buildURI, parseURI, normalizeClaimUrl, getCorrectedChannelUri } = require('./lbryURI');
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Respect ignoreRedirect when corrected URI resolves.

resolveClaimOrRedirect is called with ignoreRedirect=true for embed/playlist flows, but the corrected-URL branch always redirects. That bypasses the contract and can kick embed requests to the normal page. Gate the redirect on ignoreRedirect, and return the claim otherwise.

Suggested fix
-        if (correctedUrl) {
-          const correctedResponse = await Lbry.resolve({ urls: [correctedUrl] });
-          if (correctedResponse && correctedResponse[correctedUrl] && !correctedResponse[correctedUrl].error) {
-            // Redirect to the correct URL with @ prefix
-            const correctedWebUrl = correctedUrl.replace('lbry://', '/').replace(/#/g, ':');
-            ctx.redirect(correctedWebUrl);
-            return;
-          }
-        }
+        if (correctedUrl) {
+          const correctedResponse = await Lbry.resolve({ urls: [correctedUrl] });
+          if (correctedResponse && correctedResponse[correctedUrl] && !correctedResponse[correctedUrl].error) {
+            if (!ignoreRedirect) {
+              const correctedWebUrl = correctedUrl.replace('lbry://', '/').replace(/#/g, ':');
+              ctx.redirect(correctedWebUrl);
+              return;
+            }
+            claim = correctedResponse[correctedUrl];
+          }
+        }

Also applies to: 496-507

🤖 Prompt for AI Agents
In `@web/src/html.js` at line 24, In the resolveClaimOrRedirect function locate
the branch that handles a corrected URL (where
getCorrectedChannelUri/normalizeClaimUrl is used) and change it so the redirect
is conditional: if ignoreRedirect is true return the resolved claim/claim object
(no redirect) otherwise perform the existing redirect behavior; ensure you
reference resolveClaimOrRedirect and getCorrectedChannelUri (and
normalizeClaimUrl if used) when making the change and apply the same guard to
the other corrected-URL branch around lines 496-507.

Addresses an issue where channel URLs from platforms like Grok/Twitter may omit the "@" prefix.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@ui/hocs/withResolvedClaimRender/view.jsx`:
- Around line 43-76: The function getCorrectedChannelPath currently treats any
two-segment path like "name/name" as a channel by prepending "@", which can
false-positive for legitimate non-channel nested claim paths; update the
function by adding a clear JSDoc comment above getCorrectedChannelPath that
documents the assumption (this HOC only runs on claim pages, and any two-segment
path missing "@" will be treated as a channel/content path and auto-prefixed),
describe the expected input/outputs and the low-risk caveat about possible
non-channel nested paths, and include an example or note that callers should
avoid invoking this function for known non-channel routes.
🧹 Nitpick comments (1)
ui/hocs/withResolvedClaimRender/view.jsx (1)

43-76: Code duplication — consider extracting getCorrectedChannelPath to a shared utility.

This function reimplements the same logic as getCorrectedChannelWebPath from web/src/lbryURI.js. The main difference is that getCorrectedChannelPath handles browser URL paths (with leading slash), while the server-side version does not. If shared, this function could be added to ui/util/lbryURI.js with appropriate input normalization, or a shared utility module could be created to serve both client and server code paths.

Comment on lines +43 to +76
function getCorrectedChannelPath(pathname: string): ?string {
try {
// Remove leading slash
const webPath = pathname.startsWith('/') ? pathname.slice(1) : pathname;

// Must have a slash with content after it (channel/content pattern)
const slashIndex = webPath.indexOf('/');
if (slashIndex === -1 || slashIndex === webPath.length - 1) {
return null;
}

const firstPart = webPath.substring(0, slashIndex);
const secondPart = webPath.substring(slashIndex + 1);

// First part should not already start with @
if (firstPart.startsWith('@')) {
return null;
}

// Both parts should have content (non-empty name before any modifiers)
// Modifiers in web URLs use : instead of #
const firstNameMatch = firstPart.match(/^[^#:$*]+/);
const secondNameMatch = secondPart.match(/^[^#:$*]+/);

if (!firstNameMatch || !firstNameMatch[0] || !secondNameMatch || !secondNameMatch[0]) {
return null;
}

// Return the corrected path with @ prefix
return `/@${webPath}`;
} catch (e) {
return null;
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Heuristic may false-positive on non-channel two-segment claim paths.

getCorrectedChannelPath adds @ to any "name/name" path where the first segment lacks @. If a legitimate non-channel claim ever has a nested path pattern (without @), this would incorrectly redirect it. The risk is low since this HOC is only rendered for claim pages and LBRY channel/content paths use the @channel/content convention, but it's worth documenting this assumption in the function's JSDoc.

🧰 Tools
🪛 Biome (2.3.13)

[error] 43-43: Type annotations are a TypeScript only feature. Convert your file to a TypeScript file or remove the syntax.

TypeScript only syntax

(parse)


[error] 43-43: return types can only be used in TypeScript files

(parse)


[error] 43-43: Expected a function body but instead found '?'.

Expected a function body here.

(parse)


[error] 51-51: Illegal return statement outside of a function

(parse)


[error] 59-59: Illegal return statement outside of a function

(parse)


[error] 68-68: Illegal return statement outside of a function

(parse)


[error] 72-72: Illegal return statement outside of a function

(parse)


[error] 74-74: Illegal return statement outside of a function

(parse)

🤖 Prompt for AI Agents
In `@ui/hocs/withResolvedClaimRender/view.jsx` around lines 43 - 76, The function
getCorrectedChannelPath currently treats any two-segment path like "name/name"
as a channel by prepending "@", which can false-positive for legitimate
non-channel nested claim paths; update the function by adding a clear JSDoc
comment above getCorrectedChannelPath that documents the assumption (this HOC
only runs on claim pages, and any two-segment path missing "@" will be treated
as a channel/content path and auto-prefixed), describe the expected
input/outputs and the low-risk caveat about possible non-channel nested paths,
and include an example or note that callers should avoid invoking this function
for known non-channel routes.

@tzarebczan tzarebczan merged commit c8685fc into master Feb 6, 2026
3 checks passed
@tzarebczan tzarebczan deleted the fix-bad-grok-urls branch February 6, 2026 14:43
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.

1 participant