constants.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict'
  2. // Characters.
  3. var NULL = '\0'
  4. var AMP = '&'
  5. var SP = ' '
  6. var TB = '\t'
  7. var GR = '`'
  8. var DQ = '"'
  9. var SQ = "'"
  10. var EQ = '='
  11. var LT = '<'
  12. var GT = '>'
  13. var SO = '/'
  14. var LF = '\n'
  15. var CR = '\r'
  16. var FF = '\f'
  17. var whitespace = [SP, TB, LF, CR, FF]
  18. // https://html.spec.whatwg.org/#attribute-name-state
  19. var name = whitespace.concat(AMP, SO, GT, EQ)
  20. // https://html.spec.whatwg.org/#attribute-value-(unquoted)-state
  21. var unquoted = whitespace.concat(AMP, GT)
  22. var unquotedSafe = unquoted.concat(NULL, DQ, SQ, LT, EQ, GR)
  23. // https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state
  24. var singleQuoted = [AMP, SQ]
  25. // https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state
  26. var doubleQuoted = [AMP, DQ]
  27. // Maps of subsets. Each value is a matrix of tuples.
  28. // The first value causes parse errors, the second is valid.
  29. // Of both values, the first value is unsafe, and the second is safe.
  30. module.exports = {
  31. name: [
  32. [name, name.concat(DQ, SQ, GR)],
  33. [name.concat(NULL, DQ, SQ, LT), name.concat(NULL, DQ, SQ, LT, GR)]
  34. ],
  35. unquoted: [[unquoted, unquotedSafe], [unquotedSafe, unquotedSafe]],
  36. single: [
  37. [singleQuoted, singleQuoted.concat(DQ, GR)],
  38. [singleQuoted.concat(NULL), singleQuoted.concat(NULL, DQ, GR)]
  39. ],
  40. double: [
  41. [doubleQuoted, doubleQuoted.concat(SQ, GR)],
  42. [doubleQuoted.concat(NULL), doubleQuoted.concat(NULL, SQ, GR)]
  43. ]
  44. }