From 95710a4dab57af5030b418177132252e90604844 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Thu, 21 Nov 2024 15:17:00 +0100 Subject: [PATCH] fix: allow spaces in iframe query strings in HTML formatting fix #2269 --- umap/static/umap/js/modules/utils.js | 6 +++--- umap/static/umap/unittests/utils.js | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/umap/static/umap/js/modules/utils.js b/umap/static/umap/js/modules/utils.js index 2e12083e..9e4feeed 100644 --- a/umap/static/umap/js/modules/utils.js +++ b/umap/static/umap/js/modules/utils.js @@ -174,15 +174,15 @@ export function toHTML(r, options) { // iframe r = r.replace( - /{{{(h_t_t_ps?[^ |{]*)}}}/g, + /{{{(h_t_t_ps?[^|{]*)}}}/g, '
' ) r = r.replace( - /{{{(h_t_t_ps?[^ |{]*)\|(\d*)(px)?}}}/g, + /{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?}}}/g, '
' ) r = r.replace( - /{{{(h_t_t_ps?[^ |{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, + /{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, '
' ) diff --git a/umap/static/umap/unittests/utils.js b/umap/static/umap/unittests/utils.js index cc70bfee..8d097f07 100644 --- a/umap/static/umap/unittests/utils.js +++ b/umap/static/umap/unittests/utils.js @@ -147,7 +147,7 @@ describe('Utils', () => { ) }) - it('should handle iframe with height with px', () => { + it('should handle double iframe', () => { assert.equal( Utils.toHTML( 'A double iframe: {{{https://osm.org/pouet}}}{{{https://osm.org/boudin}}}' @@ -156,6 +156,15 @@ describe('Utils', () => { ) }) + it('should handle iframe with query string and space', () => { + assert.equal( + Utils.toHTML( + 'An iframe with query string: {{{https://osm.org/pouet.html?name=foobar&description=baz baz}}}' + ), + 'An iframe with query string:
' + ) + }) + it('http link with http link as parameter as variable', () => { assert.equal( Utils.toHTML('A phrase with a [[http://iframeurl.com?to=http://another.com]].'), @@ -263,6 +272,19 @@ describe('Utils', () => { ) }) + it('should process variables in http links', () => { + assert.equal( + Utils.greedyTemplate( + 'A phrase with a {{{https://osm.org/pouet?name={name}&description={description}}}}.', + { + name: 'foobar', + description: 'bazbaz', + } + ), + 'A phrase with a {{{https://osm.org/pouet?name=foobar&description=bazbaz}}}.' + ) + }) + it('should not accept dash', () => { assert.equal( Utils.greedyTemplate('A phrase with a {var-iable}.', { 'var-iable': 'value' }),