Skip to content

Commit

Permalink
fix: allow spaces in iframe query strings in HTML formatting (#2292)
Browse files Browse the repository at this point in the history
fix #2269
  • Loading branch information
yohanboniface authored Nov 22, 2024
2 parents 2008cca + 95710a4 commit 735c74d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
6 changes: 3 additions & 3 deletions umap/static/umap/js/modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ export function toHTML(r, options) {

// iframe
r = r.replace(
/{{{(h_t_t_ps?[^ |{]*)}}}/g,
/{{{(h_t_t_ps?[^|{]*)}}}/g,
'<div><iframe frameborder="0" src="$1" width="100%" height="300px"></iframe></div>'
)
r = r.replace(
/{{{(h_t_t_ps?[^ |{]*)\|(\d*)(px)?}}}/g,
/{{{(h_t_t_ps?[^|{]*)\|(\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,
/{{{(h_t_t_ps?[^|{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g,
'<div><iframe frameborder="0" src="$1" width="$4px" height="$2px"></iframe></div>'
)

Expand Down
24 changes: 23 additions & 1 deletion umap/static/umap/unittests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}}'
Expand All @@ -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: <div><iframe height="300px" width="100%" src="https://osm.org/pouet.html?name=foobar&amp;description=baz baz" frameborder="0"></iframe></div>'
)
})

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]].'),
Expand Down Expand Up @@ -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' }),
Expand Down

0 comments on commit 735c74d

Please sign in to comment.