1
0
mirror of https://github.com/twitter/twemoji.git synced 2024-06-15 03:35:16 +00:00

excluding nodeType 1 SVG elements too

This commit is contained in:
Andrea Giammarchi 2015-06-17 10:01:12 +01:00
parent f5ca4f51f9
commit 3c0c13d3a5
6 changed files with 30 additions and 9 deletions

21
test.js
View File

@ -514,4 +514,25 @@ wru.test([{
wru.assert('correct length', div.getElementsByTagName('img').length === 0);
wru.assert('expected html', div.innerHTML === '"\u2b1c\uFE0E"');
}
}, {
name: 'SVG Elements are ignored',
test: function () {
if (typeof SVGElement !== 'undefined') {
var innerHTML, div = document.createElement('div');
div.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40">' +
'<switch>' +
'<circle cx="20" cy="20" r="18" stroke="grey" stroke-width="2" fill="#99FF66" />' +
'<foreignObject>' +
'<div>I \u2764 emoji!</div>' +
'</foreignObject>' +
'</switch>' +
'</svg>';
// grab the normalized one
innerHTML = div.innerHTML;
twemoji.parse(div);
wru.assert('nothing changed', innerHTML === div.innerHTML);
} else {
wru.assert('nothing to do here');
}
}
}]);

View File

@ -516,8 +516,8 @@ function createTwemoji(re) {
// used to find HTML special chars in attributes
rescaper = /[&<>'"]/g,
// nodes with type 1 which should **not** be parsed
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,
// nodes with type 1 which should **not** be parsed (including lower case svg)
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA|[a-z]/,
// just a private shortcut
fromCharCode = String.fromCharCode;

View File

@ -239,8 +239,8 @@ define(function () {
// used to find HTML special chars in attributes
rescaper = /[&<>'"]/g,
// nodes with type 1 which should **not** be parsed
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,
// nodes with type 1 which should **not** be parsed (including lower case svg)
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA|[a-z]/,
// just a private shortcut
fromCharCode = String.fromCharCode;

View File

@ -238,8 +238,8 @@ var twemoji = (function (
// used to find HTML special chars in attributes
rescaper = /[&<>'"]/g,
// nodes with type 1 which should **not** be parsed
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,
// nodes with type 1 which should **not** be parsed (including lower case svg)
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA|[a-z]/,
// just a private shortcut
fromCharCode = String.fromCharCode;

2
twemoji.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -239,8 +239,8 @@ var twemoji = (function (
// used to find HTML special chars in attributes
rescaper = /[&<>'"]/g,
// nodes with type 1 which should **not** be parsed
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA/,
// nodes with type 1 which should **not** be parsed (including lower case svg)
shouldntBeParsed = /IFRAME|NOFRAMES|NOSCRIPT|SCRIPT|SELECT|STYLE|TEXTAREA|[a-z]/,
// just a private shortcut
fromCharCode = String.fromCharCode;