lexical icon indicating copy to clipboard operation
lexical copied to clipboard

Bug: [Playground] autolink escapes on second `.` when typing

Open zeitstein opened this issue 1 year ago • 13 comments

Steps To Reproduce

Type in e.g. https://www.foo.com in Playground. Works as expected on paste.

The current behavior

image

zeitstein avatar Dec 13 '22 10:12 zeitstein

some urls with subdomains do actually work. for example, typing https://playground.lexical.dev works. I believe this has to do with the autolink plugin itself, rather than the URL matcher used.

prestonbrown-me avatar Dec 16 '22 23:12 prestonbrown-me

I ran into the same issue and could track it to this change: https://github.com/facebook/lexical/commit/f29ab08dbf9c0b14b89ebef44fa243e712d817ad#diff-d62fd402ee470b9082046b4a435f031dd8539650efc92ac2ea645f8ded2a4c57R55

If you remove the "." from the PUNCTUATION_OR_SPACE regex, then the issue disappears.

NikolajLeischner avatar Jan 10 '23 09:01 NikolajLeischner

Closing this as I'm not sure there's much we can do here, and this is technically behaving correctly.

The regex is accounting for valid URLs which omit their subdomains (i.e. https://github.com), but it doesn't make any distinction when such a URL uses "www" as it's actual domain.

This is technically valid behaviour. URLS like https://www.org are a valid, and we want them to be recognised by the regex.

thegreatercurve avatar Feb 03 '23 11:02 thegreatercurve

this is technically behaving correctly.

imo it's most certainly a bug that https://www.google.com is not registering as a url

beefancohen avatar Feb 08 '23 16:02 beefancohen

Closing this doesn't seem very helpful. As is, the autolink-plugin is useless. It doesn't recognize most URLs with sub-domains correctly, and no URLs if you add a protocol. Note that this behavior is independent of the matchers you provide the plugin with.

NikolajLeischner avatar Feb 13 '23 09:02 NikolajLeischner

Closing this doesn't seem very helpful. As is, the autolink-plugin is useless. It doesn't recognize most URLs with sub-domains correctly, and no URLs if you add a protocol. Note that this behavior is independent of the matchers you provide the plugin with.

Agreed, this was closed prematurely, I think. We need to see what we can do to fix this.

acywatson avatar Feb 17 '23 17:02 acywatson

I ran into the same issue and could track it to this change: f29ab08#diff-d62fd402ee470b9082046b4a435f031dd8539650efc92ac2ea645f8ded2a4c57R55

If you remove the "." from the PUNCTUATION_OR_SPACE regex, then the issue disappears.

If the "." is removed from the regex, the following string will also be recognized as a URL, so it is necessary to consider another modification method. https://github.com...

Karibash avatar Feb 18 '23 14:02 Karibash

I ran into the same issue and could track it to this change: f29ab08#diff-d62fd402ee470b9082046b4a435f031dd8539650efc92ac2ea645f8ded2a4c57R55 If you remove the "." from the PUNCTUATION_OR_SPACE regex, then the issue disappears.

If the "." is removed from the regex, the following string will also be recognized as a URL, so it is necessary to consider another modification method. https://github.com...

Gotcha, I didn't test that case.. :)

NikolajLeischner avatar Mar 16 '23 13:03 NikolajLeischner

It seems that the issue with https://github.com/... being allowed might be due to a problem with the URL REGEX in packages/lexical-playground/src/plugins/AutoLinkPlugin/index.tsx:

/((https?:\/\/(www\.)?)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/.test("https://github.com...")
> true

Additionally, having the "." in PUNCTUATION_OR_SPACE causes issues with URLs that have extensions like .png functioning correctly.

I've submitted a PR to address this, and I would appreciate it if you could review it to ensure that the recognition works as intended.

#4430

NozomiSugiyama avatar Apr 30 '23 07:04 NozomiSugiyama

is there another way we could do autolinks? I meant something closer to ProseMirror's decorations where these decorations aren't actual nodes on the document, they're just text ranges that tells the view to treat differently, it's much more robust compared to node manipulation

https://prosemirror.net/docs/ref/#view.Decorations

intrnl avatar Sep 26 '23 01:09 intrnl

Can't PUNCTUATION_OR_SPACE be made configurable?

thorn0 avatar Mar 27 '24 00:03 thorn0