fix: correctly parse http link including another http link in the path (#2460)
Some checks are pending
Test & Docs / docs (push) Waiting to run
Test & Docs / tests (postgresql, 3.10) (push) Waiting to run
Test & Docs / tests (postgresql, 3.12) (push) Waiting to run
Test & Docs / lint (push) Waiting to run

fix #2457

Thoughts @jschleic ?
This commit is contained in:
Yohan Boniface 2025-01-30 09:12:05 +01:00 committed by GitHub
commit 5ab11428a5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 10 deletions

View file

@ -159,16 +159,13 @@ export function toHTML(r, options) {
r = r.replace(/\*(.*?)\*/g, '<em>$1</em>')
// links
r = r.replace(/(\[\[http)/g, '[[h_t_t_p') // Escape for avoiding clash between [[http://xxx]] and http://xxx
r = r.replace(/({{http)/g, '{{h_t_t_p')
r = r.replace(/(=http)/g, '=h_t_t_p') // http://xxx as query string, see https://github.com/umap-project/umap/issues/607
r = r.replace(/(https?:[^ \<)\n]*)/g, `<a target="_${target}" href="$1">$1</a>`)
r = r.replace(
/\[\[(h_t_t_ps?:[^\]|]*?)\]\]/g,
`<a target="_${target}" href="$1">$1</a>`
/(^|\s|>|\()(https?:[^ \<)\n]*)/g,
`$1<a target="_${target}" href="$2">$2</a>`
)
r = r.replace(/\[\[(https?:[^\]|]*?)\]\]/g, `<a target="_${target}" href="$1">$1</a>`)
r = r.replace(
/\[\[(h_t_t_ps?:[^|]*?)\|(.*?)\]\]/g,
/\[\[(https?:[^|]*?)\|(.*?)\]\]/g,
`<a target="_${target}" href="$1">$2</a>`
)
r = r.replace(/\[\[([^\]|]*?)\]\]/g, `<a target="_${target}" href="$1">$1</a>`)
@ -176,15 +173,15 @@ export function toHTML(r, options) {
// iframe
r = r.replace(
/{{{(h_t_t_ps?[^|{]*)}}}/g,
/{{{(https?[^|{]*)}}}/g,
'<div><iframe frameborder="0" src="$1" width="100%" height="300px"></iframe></div>'
)
r = r.replace(
/{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?}}}/g,
/{{{(https?[^|{]*)\|(\d*)(px)?}}}/g,
'<div><iframe frameborder="0" src="$1" width="100%" height="$2px"></iframe></div>'
)
r = r.replace(
/{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g,
/{{{(https?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g,
'<div><iframe frameborder="0" src="$1" width="$4px" height="$2px"></iframe></div>'
)

View file

@ -54,6 +54,13 @@ describe('Utils', () => {
)
})
it('should handle links with another url in path', () => {
assert.equal(
Utils.toHTML('A simple https://osm.org/https://anotherurl.com link'),
'A simple <a href="https://osm.org/https://anotherurl.com" target="_blank">https://osm.org/https://anotherurl.com</a> link'
)
})
it('should handle simple link inside parenthesis', () => {
assert.equal(
Utils.toHTML('A simple link (http://osm.org)'),
@ -172,6 +179,13 @@ describe('Utils', () => {
)
})
it('http link with http link as in path', () => {
assert.equal(
Utils.toHTML('A phrase with a [[https://iframeurl.com/https://another.com]].'),
'A phrase with a <a href="https://iframeurl.com/https://another.com" target="_blank">https://iframeurl.com/https://another.com</a>.'
)
})
it('simple bullet points', () => {
assert.equal(
Utils.toHTML('* First point\n* Second point\n* Last point'),