Fix parsing iframe when text contain two iframes

cf #689
This commit is contained in:
Yohan Boniface 2019-05-11 11:10:03 +02:00
parent 0b2f9b5c12
commit 70a760489e
2 changed files with 7 additions and 3 deletions

View file

@ -81,9 +81,9 @@ L.Util.toHTML = function (r) {
r = r.replace(/\[\[([^|]*?)\|(.*?)\]\]/g, '<a href="$1">$2</a>'); r = r.replace(/\[\[([^|]*?)\|(.*?)\]\]/g, '<a href="$1">$2</a>');
// iframe // iframe
r = r.replace(/{{{(h_t_t_ps?[^ |]*)}}}/g, '<iframe frameborder="0" src="$1" width="100%" height="300px"></iframe>'); r = r.replace(/{{{(h_t_t_ps?[^ |{]*)}}}/g, '<iframe frameborder="0" src="$1" width="100%" height="300px"></iframe>');
r = r.replace(/{{{(h_t_t_ps?[^ |]*)\|(\d*)(px)?}}}/g, '<iframe frameborder="0" src="$1" width="100%" height="$2px"></iframe>'); r = r.replace(/{{{(h_t_t_ps?[^ |{]*)\|(\d*)(px)?}}}/g, '<iframe frameborder="0" src="$1" width="100%" height="$2px"></iframe>');
r = r.replace(/{{{(h_t_t_ps?[^ |]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, '<iframe frameborder="0" src="$1" width="$4px" height="$2px"></iframe>'); r = r.replace(/{{{(h_t_t_ps?[^ |{]*)\|(\d*)(px)?\*(\d*)(px)?}}}/g, '<iframe frameborder="0" src="$1" width="$4px" height="$2px"></iframe>');
// images // images
r = r.replace(/{{([^\]|]*?)}}/g, '<img src="$1">'); r = r.replace(/{{([^\]|]*?)}}/g, '<img src="$1">');

View file

@ -94,6 +94,10 @@ describe('L.Util', function () {
assert.equal(L.Util.toHTML('A simple iframe: {{{https://osm.org/?url=https%3A//anotherurl.com}}}'), 'A simple iframe: <iframe frameborder="0" src="https://osm.org/?url=https%3A//anotherurl.com" width="100%" height="300px"></iframe>'); assert.equal(L.Util.toHTML('A simple iframe: {{{https://osm.org/?url=https%3A//anotherurl.com}}}'), 'A simple iframe: <iframe frameborder="0" src="https://osm.org/?url=https%3A//anotherurl.com" width="100%" height="300px"></iframe>');
}); });
it('should handle iframe with height with px', function () {
assert.equal(L.Util.toHTML('A double iframe: {{{https://osm.org/pouet}}}{{{https://osm.org/boudin}}}'), 'A double iframe: <iframe frameborder="0" src="https://osm.org/pouet" width="100%" height="300px"></iframe><iframe frameborder="0" src="https://osm.org/boudin" width="100%" height="300px"></iframe>');
});
it('http link with http link as parameter as variable', function () { it('http link with http link as parameter as variable', function () {
assert.equal(L.Util.toHTML('A phrase with a [[http://iframeurl.com?to=http://another.com]].'), 'A phrase with a <a target="_blank" href="http://iframeurl.com?to=http://another.com">http://iframeurl.com?to=http://another.com</a>.'); assert.equal(L.Util.toHTML('A phrase with a [[http://iframeurl.com?to=http://another.com]].'), 'A phrase with a <a target="_blank" href="http://iframeurl.com?to=http://another.com">http://iframeurl.com?to=http://another.com</a>.');
}); });