in Ox.sanitizeHTML, allow mailto: links
This commit is contained in:
parent
17983efc47
commit
cc29f8f832
1 changed files with 33 additions and 64 deletions
|
@ -49,7 +49,7 @@
|
|||
tag: {
|
||||
a: [
|
||||
[
|
||||
/<a [^<>]*?href="((https?:\/\/|\/).+?)".*?>/gi,
|
||||
/<a [^<>]*?href="((https?:\/\/|mailto:|\/).+?)".*?>/gi,
|
||||
'<a href="{1}">',
|
||||
],
|
||||
[
|
||||
|
@ -333,12 +333,16 @@
|
|||
Ox.sanitizeHTML <f> Takes untrusted HTML and returns something trustworthy
|
||||
> Ox.sanitizeHTML('http://foo.com, bar')
|
||||
'<a href="http://foo.com">http://foo.com</a>, bar'
|
||||
> Ox.sanitizeHTML('http://foo.com/foobar?foo, bar')
|
||||
'<a href="http://foo.com/foobar?foo">http://foo.com/foobar?foo</a>, bar'
|
||||
> Ox.sanitizeHTML('http://foo.com/foo?bar, bar')
|
||||
'<a href="http://foo.com/foo?bar">http://foo.com/foo?bar</a>, bar'
|
||||
> Ox.sanitizeHTML('(see: www.foo.com)')
|
||||
'(see: <a href="http://www.foo.com">www.foo.com</a>)'
|
||||
> Ox.sanitizeHTML('foo@bar.com')
|
||||
'<a href="mailto:foo@bar.com">foo@bar.com</a>'
|
||||
> Ox.sanitizeHTML('<a href="mailto:foo@bar.com">foo</a>')
|
||||
'<a href="mailto:foo@bar.com">foo</a>'
|
||||
> Ox.sanitizeHTML('<a href="http://foo.com">foo</a>')
|
||||
'<a href="http://foo.com">foo</a>'
|
||||
> Ox.sanitizeHTML('<a href="http://foo.com" onclick="alert()">foo</a>')
|
||||
'<a href="http://foo.com">foo</a>'
|
||||
> Ox.sanitizeHTML('<a href="javascript:alert()">foo</a>')
|
||||
|
@ -356,46 +360,12 @@
|
|||
> Ox.sanitizeHTML('<b>foo</b></b>')
|
||||
'<b>foo</b>'
|
||||
@*/
|
||||
Ox.sanitizeHTML = (function() {
|
||||
var defaultTags = [
|
||||
// inline formatting
|
||||
'b', 'code', 'i', 's', 'sub', 'sup', 'u',
|
||||
// block formatting
|
||||
'blockquote', 'h1', 'h2', 'h3', 'p', 'pre',
|
||||
// lists
|
||||
'li', 'ol', 'ul',
|
||||
// tables
|
||||
'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr',
|
||||
// other
|
||||
'a', 'br', 'img',
|
||||
// special
|
||||
'rtl', '[]'
|
||||
],
|
||||
parse = {
|
||||
a: {
|
||||
'<a [^<>]*?href="((https?:\/\/|\/).+?)".*?>': '<a href="{1}">',
|
||||
'<\/a>': '</a>'
|
||||
},
|
||||
img: {
|
||||
'<img [^<>]*?src="((https?:\/\/|\/).+?)".*?>': '<img src="{1}">'
|
||||
},
|
||||
rtl: {
|
||||
'<rtl>': '<div style="direction: rtl">',
|
||||
'<\/rtl>': '</div>'
|
||||
},
|
||||
'*': function(tag) {
|
||||
var ret = {};
|
||||
ret['<(/?' + tag + ') ?/?>'] = '<{1}>';
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
tab = '\t';
|
||||
return function(html, tags, wikilinks) {
|
||||
Ox.sanitizeHTML = function(html, tags) {
|
||||
var matches = [];
|
||||
tags = tags || defaultTags;
|
||||
// html = Ox.clean(html); fixme: can this be a parameter?
|
||||
if (tags.indexOf('[]') > -1) {
|
||||
html = html.replace(/\[((https?:\/\/|\/).+?) (.+?)\]/gi, '<a href="$1">$3</a>');
|
||||
html = html.replace(/\[((https?:\/\/|mailto:|\/).+?) (.+?)\]/gi, '<a href="$1">$3</a>');
|
||||
tags = tags.filter(function(tag) {
|
||||
return tag != '[]';
|
||||
});
|
||||
|
@ -418,6 +388,5 @@
|
|||
// Note: this converts ''' to "'" and '"' to '"'
|
||||
return Ox.normalizeHTML(html);
|
||||
};
|
||||
}());
|
||||
|
||||
}());
|
||||
|
|
Loading…
Reference in a new issue