You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

223 lines
4.4 KiB

  1. // Copyright (C) MongoDB, Inc. 2017-present.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License"); you may
  4. // not use this file except in compliance with the License. You may obtain
  5. // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Based on github.com/golang/go by The Go Authors
  8. // See THIRD-PARTY-NOTICES for original license terms.
  9. package bsonrw
  10. import "unicode/utf8"
  11. // safeSet holds the value true if the ASCII character with the given array
  12. // position can be represented inside a JSON string without any further
  13. // escaping.
  14. //
  15. // All values are true except for the ASCII control characters (0-31), the
  16. // double quote ("), and the backslash character ("\").
  17. var safeSet = [utf8.RuneSelf]bool{
  18. ' ': true,
  19. '!': true,
  20. '"': false,
  21. '#': true,
  22. '$': true,
  23. '%': true,
  24. '&': true,
  25. '\'': true,
  26. '(': true,
  27. ')': true,
  28. '*': true,
  29. '+': true,
  30. ',': true,
  31. '-': true,
  32. '.': true,
  33. '/': true,
  34. '0': true,
  35. '1': true,
  36. '2': true,
  37. '3': true,
  38. '4': true,
  39. '5': true,
  40. '6': true,
  41. '7': true,
  42. '8': true,
  43. '9': true,
  44. ':': true,
  45. ';': true,
  46. '<': true,
  47. '=': true,
  48. '>': true,
  49. '?': true,
  50. '@': true,
  51. 'A': true,
  52. 'B': true,
  53. 'C': true,
  54. 'D': true,
  55. 'E': true,
  56. 'F': true,
  57. 'G': true,
  58. 'H': true,
  59. 'I': true,
  60. 'J': true,
  61. 'K': true,
  62. 'L': true,
  63. 'M': true,
  64. 'N': true,
  65. 'O': true,
  66. 'P': true,
  67. 'Q': true,
  68. 'R': true,
  69. 'S': true,
  70. 'T': true,
  71. 'U': true,
  72. 'V': true,
  73. 'W': true,
  74. 'X': true,
  75. 'Y': true,
  76. 'Z': true,
  77. '[': true,
  78. '\\': false,
  79. ']': true,
  80. '^': true,
  81. '_': true,
  82. '`': true,
  83. 'a': true,
  84. 'b': true,
  85. 'c': true,
  86. 'd': true,
  87. 'e': true,
  88. 'f': true,
  89. 'g': true,
  90. 'h': true,
  91. 'i': true,
  92. 'j': true,
  93. 'k': true,
  94. 'l': true,
  95. 'm': true,
  96. 'n': true,
  97. 'o': true,
  98. 'p': true,
  99. 'q': true,
  100. 'r': true,
  101. 's': true,
  102. 't': true,
  103. 'u': true,
  104. 'v': true,
  105. 'w': true,
  106. 'x': true,
  107. 'y': true,
  108. 'z': true,
  109. '{': true,
  110. '|': true,
  111. '}': true,
  112. '~': true,
  113. '\u007f': true,
  114. }
  115. // htmlSafeSet holds the value true if the ASCII character with the given
  116. // array position can be safely represented inside a JSON string, embedded
  117. // inside of HTML <script> tags, without any additional escaping.
  118. //
  119. // All values are true except for the ASCII control characters (0-31), the
  120. // double quote ("), the backslash character ("\"), HTML opening and closing
  121. // tags ("<" and ">"), and the ampersand ("&").
  122. var htmlSafeSet = [utf8.RuneSelf]bool{
  123. ' ': true,
  124. '!': true,
  125. '"': false,
  126. '#': true,
  127. '$': true,
  128. '%': true,
  129. '&': false,
  130. '\'': true,
  131. '(': true,
  132. ')': true,
  133. '*': true,
  134. '+': true,
  135. ',': true,
  136. '-': true,
  137. '.': true,
  138. '/': true,
  139. '0': true,
  140. '1': true,
  141. '2': true,
  142. '3': true,
  143. '4': true,
  144. '5': true,
  145. '6': true,
  146. '7': true,
  147. '8': true,
  148. '9': true,
  149. ':': true,
  150. ';': true,
  151. '<': false,
  152. '=': true,
  153. '>': false,
  154. '?': true,
  155. '@': true,
  156. 'A': true,
  157. 'B': true,
  158. 'C': true,
  159. 'D': true,
  160. 'E': true,
  161. 'F': true,
  162. 'G': true,
  163. 'H': true,
  164. 'I': true,
  165. 'J': true,
  166. 'K': true,
  167. 'L': true,
  168. 'M': true,
  169. 'N': true,
  170. 'O': true,
  171. 'P': true,
  172. 'Q': true,
  173. 'R': true,
  174. 'S': true,
  175. 'T': true,
  176. 'U': true,
  177. 'V': true,
  178. 'W': true,
  179. 'X': true,
  180. 'Y': true,
  181. 'Z': true,
  182. '[': true,
  183. '\\': false,
  184. ']': true,
  185. '^': true,
  186. '_': true,
  187. '`': true,
  188. 'a': true,
  189. 'b': true,
  190. 'c': true,
  191. 'd': true,
  192. 'e': true,
  193. 'f': true,
  194. 'g': true,
  195. 'h': true,
  196. 'i': true,
  197. 'j': true,
  198. 'k': true,
  199. 'l': true,
  200. 'm': true,
  201. 'n': true,
  202. 'o': true,
  203. 'p': true,
  204. 'q': true,
  205. 'r': true,
  206. 's': true,
  207. 't': true,
  208. 'u': true,
  209. 'v': true,
  210. 'w': true,
  211. 'x': true,
  212. 'y': true,
  213. 'z': true,
  214. '{': true,
  215. '|': true,
  216. '}': true,
  217. '~': true,
  218. '\u007f': true,
  219. }