Tweak parsing links

This commit is contained in:
Jon Staab
2025-10-16 16:19:23 -07:00
parent 9e628b14e2
commit 080731c88b
2 changed files with 25 additions and 6 deletions
+24 -5
View File
@@ -249,12 +249,31 @@ export const parseInvoice = (text: string, context: ParseContext): ParsedInvoice
export const parseLink = (text: string, context: ParseContext): ParsedLink | void => {
const prev = last(context.results)
const link = text.match(
/^([a-z\+:]{2,30}:\/\/)?[-\.~\w]+\.[\w]{2,6}([^\s]*[^<>"'\.!,:\s\)\(]+)?/gi,
)?.[0]
// Skip url if it's just the end of a filepath or an ellipse
if (!link || (prev?.type === ParsedType.Text && prev.value.endsWith("/")) || link.match(/\.\./)) {
// Skip if it's just the end of a filepath
if (prev?.type === ParsedType.Text && prev.value.endsWith("/")) {
return
}
const regexes = [
// Anything with a protocol before it
/^([a-z\+:]{2,30}:\/\/)[-\.~\w]+([^\s]*[^<>"'\.!,:\s\)\(]+)?/gi,
// Stuff without a protocol, but with a dot
/^\w+[-\.~\w]+\.[\w]{2,6}([^\s]*[^<>"'\.!,:\s\)\(]+)?/gi,
]
let link = ""
for (const regex of regexes) {
const match = text.match(regex)
if (match) {
link = match[0]
break
}
}
// Skip url if it's an ellipse
if (!link || link.match(/\.\./)) {
return
}
+1 -1
View File
@@ -148,7 +148,7 @@ export const diff = async ({relays, filters, ...options}: DiffOptions) => {
resolve({relay, have: diff.have, need: diff.need})
})
diff.on(DifferenceEvent.Error, (url, message) => {
diff.on(DifferenceEvent.Error, (message, url) => {
console.warn(`Negentropy error on ${url}: ${message}`)
})