reorder regexp, add test

This commit is contained in:
rolux 2012-05-27 13:40:19 +02:00
parent cc29f8f832
commit ccae6e4997

View file

@ -49,7 +49,7 @@
tag: { tag: {
a: [ a: [
[ [
/<a [^<>]*?href="((https?:\/\/|mailto:|\/).+?)".*?>/gi, /<a [^<>]*?href="((\/|https?:\/\/|mailto:).+?)".*?>/gi,
'<a href="{1}">', '<a href="{1}">',
], ],
[ [
@ -59,7 +59,7 @@
], ],
img: [ img: [
[ [
/<img [^<>]*?src="((https?:\/\/|\/).+?)".*?>/gi, /<img [^<>]*?src="((\/|https?:\/\/).+?)".*?>/gi,
'<img src="$1">' '<img src="$1">'
] ]
], ],
@ -347,6 +347,8 @@
'<a href="http://foo.com">foo</a>' '<a href="http://foo.com">foo</a>'
> Ox.sanitizeHTML('<a href="javascript:alert()">foo</a>') > Ox.sanitizeHTML('<a href="javascript:alert()">foo</a>')
'&lt;a href="javascript:alert()"&gt;foo' '&lt;a href="javascript:alert()"&gt;foo'
> Ox.sanitizeHTML('<a href="/foo">foo</a>')
'<a href="/foo">foo</a>'
> Ox.sanitizeHTML('[http://foo.com foo]') > Ox.sanitizeHTML('[http://foo.com foo]')
'<a href="http://foo.com">foo</a>' '<a href="http://foo.com">foo</a>'
> Ox.sanitizeHTML('<rtl>foo</rtl>') > Ox.sanitizeHTML('<rtl>foo</rtl>')
@ -365,7 +367,7 @@
tags = tags || defaultTags; tags = tags || defaultTags;
// html = Ox.clean(html); fixme: can this be a parameter? // html = Ox.clean(html); fixme: can this be a parameter?
if (tags.indexOf('[]') > -1) { if (tags.indexOf('[]') > -1) {
html = html.replace(/\[((https?:\/\/|mailto:|\/).+?) (.+?)\]/gi, '<a href="$1">$3</a>'); html = html.replace(/\[((\/|https?:\/\/|mailto:).+?) (.+?)\]/gi, '<a href="$1">$3</a>');
tags = tags.filter(function(tag) { tags = tags.filter(function(tag) {
return tag != '[]'; return tag != '[]';
}); });