Skip to content
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

Enhance URL parsing in regex to exclude non-Latin alphabets at the end #946

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

Conversation

notJoon
Copy link

@notJoon notJoon commented Jul 3, 2023

Description

The existing regex in function detectLinkables is unfortunately matches non-Latin characters if they are attached to the URL without a space. This behaviour leads to unexpected results, when dealing with Asian languages (e.g. can't open external links or userename).

Because Asian languages are mostly has a grammatical elements, which are appended some character to the end of a noun without a space.

스크린샷 2023-07-03 오후 5 41 48

To solve this issue, I modified the previous regex to ensure URLs end with Latin alphabet characters or numbers. The updated regex is as follows:

/((^|\s|()@[a-z0-9.-]+)|((^|\s|()https?:\/\/[\w.-]+[a-z0-9])|((^|\s|()(?<domain>[a-z][a-z0-9]*(.[a-z0-9]+)+)[a-z0-9]))))/gi
스크린샷 2023-07-03 오후 5 42 24

This regex will help to correctly parse URLs in contexts with mixed language usage.

Thanks!

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