Skip to content

Commit

Permalink
excluding nodeType 1 SVG elements too
Browse files Browse the repository at this point in the history
  • Loading branch information
WebReflection committed Jun 17, 2015
1 parent f5ca4f5 commit 3c0c13d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
21 changes: 21 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
}]);
4 changes: 2 additions & 2 deletions twemoji-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions twemoji.amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions twemoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion twemoji.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions twemoji.npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3c0c13d

Please sign in to comment.