|
1 | 1 | 'use strict' |
2 | 2 |
|
3 | | -// Characters. |
4 | | -var nil = '\0' |
5 | | -var ampersand = '&' |
6 | | -var space = ' ' |
7 | | -var tab = '\t' |
8 | | -var graveAccent = '`' |
9 | | -var quotationMark = '"' |
10 | | -var apostrophe = "'" |
11 | | -var equalsTo = '=' |
12 | | -var lessThan = '<' |
13 | | -var greaterThan = '>' |
14 | | -var slash = '/' |
15 | | -var lineFeed = '\n' |
16 | | -var carriageReturn = '\r' |
17 | | -var formFeed = '\f' |
18 | | - |
19 | | -var whitespace = [space, tab, lineFeed, carriageReturn, formFeed] |
20 | | - |
21 | | -// See: <https://html.spec.whatwg.org/#attribute-name-state>. |
22 | | -var name = whitespace.concat(ampersand, slash, greaterThan, equalsTo) |
23 | | - |
24 | | -// See: <https://html.spec.whatwg.org/#attribute-value-(unquoted)-state>. |
25 | | -var unquoted = whitespace.concat(ampersand, greaterThan) |
26 | | -var unquotedSafe = unquoted.concat( |
27 | | - nil, |
28 | | - quotationMark, |
29 | | - apostrophe, |
30 | | - lessThan, |
31 | | - equalsTo, |
32 | | - graveAccent |
33 | | -) |
34 | | - |
35 | | -// See: <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>. |
36 | | -var singleQuoted = [ampersand, apostrophe] |
37 | | - |
38 | | -// See: <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>. |
39 | | -var doubleQuoted = [ampersand, quotationMark] |
40 | | - |
41 | 3 | // Maps of subsets. |
42 | 4 | // Each value is a matrix of tuples. |
43 | 5 | // The first value causes parse errors, the second is valid. |
44 | 6 | // Of both values, the first value is unsafe, and the second is safe. |
45 | 7 | module.exports = { |
| 8 | + // See: <https://html.spec.whatwg.org/#attribute-name-state>. |
46 | 9 | name: [ |
47 | | - [name, name.concat(quotationMark, apostrophe, graveAccent)], |
48 | | - [ |
49 | | - name.concat(nil, quotationMark, apostrophe, lessThan), |
50 | | - name.concat(nil, quotationMark, apostrophe, lessThan, graveAccent) |
51 | | - ] |
| 10 | + ['\t\n\f\r &/=>'.split(''), '\t\n\f\r "&\'/=>`'.split('')], |
| 11 | + ['\0\t\n\f\r "&\'/<=>'.split(''), '\0\t\n\f\r "&\'/<=>`'.split('')] |
52 | 12 | ], |
| 13 | + // See: <https://html.spec.whatwg.org/#attribute-value-(unquoted)-state>. |
53 | 14 | unquoted: [ |
54 | | - [unquoted, unquotedSafe], |
55 | | - [unquotedSafe, unquotedSafe] |
| 15 | + ['\t\n\f\r &>'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')], |
| 16 | + ['\0\t\n\f\r "&\'<=>`'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')] |
56 | 17 | ], |
| 18 | + // See: <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>. |
57 | 19 | single: [ |
58 | | - [singleQuoted, singleQuoted.concat(quotationMark, graveAccent)], |
59 | | - [ |
60 | | - singleQuoted.concat(nil), |
61 | | - singleQuoted.concat(nil, quotationMark, graveAccent) |
62 | | - ] |
| 20 | + ["&'".split(''), '"&\'`'.split('')], |
| 21 | + ["\0&'".split(''), '\0"&\'`'.split('')] |
63 | 22 | ], |
| 23 | + // See: <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>. |
64 | 24 | double: [ |
65 | | - [doubleQuoted, doubleQuoted.concat(apostrophe, graveAccent)], |
66 | | - [ |
67 | | - doubleQuoted.concat(nil), |
68 | | - doubleQuoted.concat(nil, apostrophe, graveAccent) |
69 | | - ] |
| 25 | + ['"&'.split(''), '"&\'`'.split('')], |
| 26 | + ['\0"&'.split(''), '\0"&\'`'.split('')] |
70 | 27 | ] |
71 | 28 | } |
0 commit comments