Skip to content

Commit 9ed9eb0

Browse files
committed
Add IE11 support using minimal polyfill
1 parent 5eb9357 commit 9ed9eb0

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/striptags.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
(function (global) {
44

5+
// minimal symbol polyfill for IE11 and others
6+
if (typeof Symbol !== 'function') {
7+
var Symbol = function(name) {
8+
return name;
9+
}
10+
11+
Symbol.nonNative = true;
12+
}
13+
514
const STATE_PLAINTEXT = Symbol('plaintext');
615
const STATE_HTML = Symbol('html');
716
const STATE_COMMENT = Symbol('comment');
@@ -36,8 +45,8 @@
3645
allowable_tags = parse_allowable_tags(allowable_tags);
3746

3847
return {
39-
allowable_tags,
40-
tag_replacement,
48+
allowable_tags : allowable_tags,
49+
tag_replacement: tag_replacement,
4150

4251
state : STATE_PLAINTEXT,
4352
tag_buffer : '',
@@ -179,21 +188,28 @@
179188
}
180189

181190
function parse_allowable_tags(allowable_tags) {
182-
let tags_array = [];
191+
let tag_set = new Set();
183192

184193
if (typeof allowable_tags === 'string') {
185194
let match;
186195

187-
while ((match = ALLOWED_TAGS_REGEX.exec(allowable_tags)) !== null) {
188-
tags_array.push(match[1]);
196+
while ((match = ALLOWED_TAGS_REGEX.exec(allowable_tags))) {
197+
tag_set.add(match[1]);
189198
}
190199
}
191200

192-
else if (typeof allowable_tags[Symbol.iterator] === 'function') {
193-
tags_array = allowable_tags;
201+
else if (!Symbol.nonNative &&
202+
typeof allowable_tags[Symbol.iterator] === 'function') {
203+
204+
tag_set = new Set(allowable_tags);
205+
}
206+
207+
else if (typeof allowable_tags.forEach === 'function') {
208+
// IE11 compatible
209+
allowable_tags.forEach(tag_set.add, tag_set);
194210
}
195211

196-
return new Set(tags_array);
212+
return tag_set;
197213
}
198214

199215
function normalize_tag(tag_buffer) {

0 commit comments

Comments
 (0)