From f0751ec5dd938e2b8c93bcc9030b26a6f62e4fce Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 29 Jan 2025 20:23:43 +0100 Subject: [PATCH] fix: correctly parse http link including another http link in the path fix #2457 --- umap/static/umap/js/modules/utils.js | 17 +++++++---------- umap/static/umap/unittests/utils.js | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 3f9fdf0e..228d94c1 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -159,16 +159,13 @@ export function toHTML(r, options) { r = r.replace(/\*(.*?)\*/g, '$1') // 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, `$1`) r = r.replace( - /\[\[(h_t_t_ps?:[^\]|]*?)\]\]/g, - `$1` + /(^|\s|>|\()(https?:[^ \<)\n]*)/g, + `$1$2` ) + r = r.replace(/\[\[(https?:[^\]|]*?)\]\]/g, `$1`) r = r.replace( - /\[\[(h_t_t_ps?:[^|]*?)\|(.*?)\]\]/g, + /\[\[(https?:[^|]*?)\|(.*?)\]\]/g, `$2` ) r = r.replace(/\[\[([^\]|]*?)\]\]/g, `$1`) @@ -176,15 +173,15 @@ export function toHTML(r, options) { // iframe r = r.replace( - /{{{(h_t_t_ps?[^|{]*)}}}/g, + /{{{(https?[^|{]*)}}}/g, '
' ) r = r.replace( - /{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?}}}/g, + /{{{(https?[^|{]*)\|(\d*)(px)?}}}/g, '
' ) r = r.replace( - /{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, + /{{{(https?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, '
' ) diff --git a/umap/static/umap/unittests/utils.js b/umap/static/umap/unittests/utils.js index 8d097f07..fb06900b 100644 --- a/umap/static/umap/unittests/utils.js +++ b/umap/static/umap/unittests/utils.js @@ -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 https://osm.org/https://anotherurl.com 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 https://iframeurl.com/https://another.com.' + ) + }) + it('simple bullet points', () => { assert.equal( Utils.toHTML('* First point\n* Second point\n* Last point'),