Skip to content

Commit

Permalink
fix(richtext-lexical): auto link node escapes on second "."
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Jul 2, 2024
1 parent dfa6b08 commit 98ff746
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ function startsWithSeparator(textContent: string): boolean {
return isSeparator(textContent[0])
}

function startsWithFullStop(textContent: string): boolean {
return /^\.[a-z\d]+/i.test(textContent)
}

function isPreviousNodeValid(node: LexicalNode): boolean {
let previousNode = node.getPreviousSibling()
if ($isElementNode(previousNode)) {
Expand Down Expand Up @@ -340,7 +344,10 @@ function handleBadNeighbors(
const nextSibling = textNode.getNextSibling()
const text = textNode.getTextContent()

if ($isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) {
if (
$isAutoLinkNode(previousSibling) &&
(!startsWithSeparator(text) || startsWithFullStop(text))
) {
previousSibling.append(textNode)
handleLinkEdit(previousSibling, matchers, onChange)
onChange(null, previousSibling.getFields()?.url ?? null)
Expand Down Expand Up @@ -418,7 +425,7 @@ function useAutoLink(
}

const URL_REGEX =
/((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)/
/((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)(?<![-.+():%])/

const EMAIL_REGEX =
/(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))/i
Expand Down

0 comments on commit 98ff746

Please sign in to comment.