Skip to content

Fix(npub): Do not parse npubs in links #2253

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brymut
Copy link
Contributor

@brymut brymut commented Jun 28, 2025

Description

Add check to prevent parsing of npubs in links.

closes #2252

Screenshots

Before fix
Screenshot 2025-06-28 at 17 28 18

After fix
Screenshot 2025-06-28 at 17 27 37

Additional Context

Was anything unclear during your work on this PR? Anything we should definitely take a closer look at?

Checklist

Are your changes backward compatible? Please answer below:
Y
For example, a change is not backward compatible if you removed a GraphQL field or dropped a database column.

On a scale of 1-10 how well and how have you QA'd this change and any features it might affect? Please answer below:
10

For frontend changes: Tested on mobile, light and dark mode? Please answer below:

Did you introduce any new environment variables? If so, call them out explicitly here:
N

@brymut brymut requested a review from ekzyis June 28, 2025 14:35
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

This wasn't specified in the ticket because, at the time, I wasn't aware of it, but if there's only a link, it will still parse the npub in the link to show the nostr embed.

I consider this part of the issue.

@brymut brymut force-pushed the fix/npub-parsing-in-link branch from 51d9ca8 to e039a31 Compare July 3, 2025 11:45
cursor[bot]

This comment was marked as outdated.

@brymut
Copy link
Contributor Author

brymut commented Jul 3, 2025

if there's only a link, it will still parse the npub in the link to show the nostr embed.

Ahh right, missed that too. Think I got a fix for that too.

Screenshot 2025-07-03 at 14 44 27

@brymut brymut force-pushed the fix/npub-parsing-in-link branch from e039a31 to 879f6b2 Compare July 3, 2025 12:00
@brymut brymut requested a review from ekzyis July 3, 2025 12:00
cursor[bot]

This comment was marked as outdated.

@brymut brymut force-pushed the fix/npub-parsing-in-link branch from 879f6b2 to 65bf754 Compare July 3, 2025 12:02
Copy link
Member

@ekzyis ekzyis left a comment

Choose a reason for hiding this comment

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

This removed all nostr embeds except for link posts.

This should be parsed as a nostr embed:

https://njump.me/npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk

This should be parsed as a link to njump:

npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk

This should stay a raw link:

https://npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk.nsite.lol

@brymut
Copy link
Contributor Author

brymut commented Jul 5, 2025

😅 This has got quite complex/confusing for me, let me have another look

@ekzyis ekzyis marked this pull request as draft July 6, 2025 16:22
@brymut brymut force-pushed the fix/npub-parsing-in-link branch from 65bf754 to 82ba456 Compare July 7, 2025 13:08
@brymut brymut marked this pull request as ready for review July 7, 2025 13:08
@brymut
Copy link
Contributor Author

brymut commented Jul 7, 2025

This should be parsed as a nostr embed:

https://njump.me/npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk

This should be parsed as a link to njump:

npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk

This should stay a raw link:

https://npub1nsyte9neefm3jle7dg5gw6mhchxyk75a6f5dng70l4l3a2mx0nashqv2jk.nsite.lol

Ok, just tested using this link & previously discussed points. I think this solution should work.
Screenshot 2025-07-07 at 16 09 36

cursor[bot]

This comment was marked as outdated.

@brymut brymut force-pushed the fix/npub-parsing-in-link branch from 82ba456 to f6cff35 Compare July 7, 2025 13:30
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Nostr Link Embedding Logic Fails

The updated link processing logic introduces two regressions for Nostr links:

  1. njump.me Nostr links are unconditionally converted to embeds, disregarding the textOnly and !hasTextSibling constraints. This results in unwanted embeds for links with surrounding text or custom link text.
  2. Nostr links from other domains are explicitly prevented from becoming embeds, causing them to incorrectly render as autolinks even when they meet the textOnly and !hasTextSibling criteria for embed conversion.

lib/rehype-sn.js#L94-L100

if (embed?.provider === 'nostr' && host === 'njump.me') {
node.tagName = 'embed'
node.properties = { ...embed, src: href }
return
}
if (embed && embed.provider !== 'nostr' && textOnly && !hasTextSibling) {

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@brymut
Copy link
Contributor Author

brymut commented Jul 7, 2025

Bugs as described by cursor are not described in spec. Either incorrect UX behaviour or undiscussed. I can confirm that everything discussed by human review on this PR has been addressed.

edit: not even sure I'll qualify for the rewards based on the number of reviews introduced by cursor and spec changes. 🥲

@brymut brymut requested a review from ekzyis July 7, 2025 13:44
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.

Don't parse npubs in links
2 participants