|
2 | 2 |
|
3 | 3 | (function (global) { |
4 | 4 |
|
| 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 | + |
5 | 14 | const STATE_PLAINTEXT = Symbol('plaintext'); |
6 | 15 | const STATE_HTML = Symbol('html'); |
7 | 16 | const STATE_COMMENT = Symbol('comment'); |
|
36 | 45 | allowable_tags = parse_allowable_tags(allowable_tags); |
37 | 46 |
|
38 | 47 | return { |
39 | | - allowable_tags, |
40 | | - tag_replacement, |
| 48 | + allowable_tags : allowable_tags, |
| 49 | + tag_replacement: tag_replacement, |
41 | 50 |
|
42 | 51 | state : STATE_PLAINTEXT, |
43 | 52 | tag_buffer : '', |
|
179 | 188 | } |
180 | 189 |
|
181 | 190 | function parse_allowable_tags(allowable_tags) { |
182 | | - let tags_array = []; |
| 191 | + let tag_set = new Set(); |
183 | 192 |
|
184 | 193 | if (typeof allowable_tags === 'string') { |
185 | 194 | let match; |
186 | 195 |
|
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]); |
189 | 198 | } |
190 | 199 | } |
191 | 200 |
|
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); |
194 | 210 | } |
195 | 211 |
|
196 | | - return new Set(tags_array); |
| 212 | + return tag_set; |
197 | 213 | } |
198 | 214 |
|
199 | 215 | function normalize_tag(tag_buffer) { |
|
0 commit comments