RFC7159 7159

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +61 -0
  3. data/.rspec +4 -0
  4. data/.yardopts +2 -0
  5. data/Gemfile +46 -0
  6. data/LICENSE.txt +40 -0
  7. data/README.txt +899 -0
  8. data/RFC7159 +899 -0
  9. data/RFC7159.gemspec +85 -0
  10. data/Rakefile +82 -0
  11. data/lib/RFC7159.rb +80 -0
  12. data/lib/RFC7159/array.rb +134 -0
  13. data/lib/RFC7159/dumper.rb +231 -0
  14. data/lib/RFC7159/false.rb +79 -0
  15. data/lib/RFC7159/null.rb +79 -0
  16. data/lib/RFC7159/number.rb +149 -0
  17. data/lib/RFC7159/object.rb +140 -0
  18. data/lib/RFC7159/parser.ry +267 -0
  19. data/lib/RFC7159/string.rb +221 -0
  20. data/lib/RFC7159/true.rb +79 -0
  21. data/lib/RFC7159/value.rb +96 -0
  22. data/lib/RFC7159/version.rb +48 -0
  23. data/spec/RFC7159_spec.rb +275 -0
  24. data/spec/acceptance/README.txt +66 -0
  25. data/spec/acceptance/invalid/0001-ws/0001-verical-tab.txt +1 -0
  26. data/spec/acceptance/invalid/0001-ws/0002-null.txt +0 -0
  27. data/spec/acceptance/invalid/0001-ws/0003-space-in-number-1.txt +1 -0
  28. data/spec/acceptance/invalid/0001-ws/0004-space-in-number-2.txt +1 -0
  29. data/spec/acceptance/invalid/0001-ws/0005-space-in-number-3.txt +1 -0
  30. data/spec/acceptance/invalid/0001-ws/0006-space-in-number-4.txt +1 -0
  31. data/spec/acceptance/invalid/0001-ws/0007-space-in-number-5.txt +1 -0
  32. data/spec/acceptance/invalid/0001-ws/0008-space-in-number-6.txt +1 -0
  33. data/spec/acceptance/invalid/0001-ws/0009-space-in-literal.txt +1 -0
  34. data/spec/acceptance/invalid/0001-ws/0010-Unicode-LINE_SEPARATOR.txt +1 -0
  35. data/spec/acceptance/invalid/0002-comments/0001-C-style.txt +1 -0
  36. data/spec/acceptance/invalid/0002-comments/0002-C-plusplus-style.txt +2 -0
  37. data/spec/acceptance/invalid/0002-comments/0003-sh-style.txt +2 -0
  38. data/spec/acceptance/invalid/0002-comments/0004-python-docstring.txt +3 -0
  39. data/spec/acceptance/invalid/0002-comments/0005-SQL-style.txt +2 -0
  40. data/spec/acceptance/invalid/0002-comments/0006-BASIC-style.txt +2 -0
  41. data/spec/acceptance/invalid/0003-literals/0001-FALSE.txt +1 -0
  42. data/spec/acceptance/invalid/0003-literals/0002-NULL.txt +1 -0
  43. data/spec/acceptance/invalid/0003-literals/0003-TRUE.txt +1 -0
  44. data/spec/acceptance/invalid/0003-literals/0004-NUL.txt +1 -0
  45. data/spec/acceptance/invalid/0003-literals/0005-nil.txt +1 -0
  46. data/spec/acceptance/invalid/0003-literals/0006-undef.txt +1 -0
  47. data/spec/acceptance/invalid/0003-literals/0007-modifier.txt +1 -0
  48. data/spec/acceptance/invalid/0003-literals/0008-undefined.txt +1 -0
  49. data/spec/acceptance/invalid/0004-numbers/0001-omit-zero.txt +1 -0
  50. data/spec/acceptance/invalid/0004-numbers/0002-minus-dot.txt +1 -0
  51. data/spec/acceptance/invalid/0004-numbers/0003-missing-frac.txt +1 -0
  52. data/spec/acceptance/invalid/0004-numbers/0004-missing-exp.txt +1 -0
  53. data/spec/acceptance/invalid/0004-numbers/0005-octal.txt +1 -0
  54. data/spec/acceptance/invalid/0004-numbers/0006-hexadecimal.txt +1 -0
  55. data/spec/acceptance/invalid/0004-numbers/0007-comma.txt +1 -0
  56. data/spec/acceptance/invalid/0004-numbers/0008-perl-underscore.txt +1 -0
  57. data/spec/acceptance/invalid/0004-numbers/0009-NaN.txt +1 -0
  58. data/spec/acceptance/invalid/0004-numbers/0010-Inf.txt +1 -0
  59. data/spec/acceptance/invalid/0004-numbers/0011-Infinity.txt +1 -0
  60. data/spec/acceptance/invalid/0005-strings/0000-NUL.txt +0 -0
  61. data/spec/acceptance/invalid/0005-strings/0001-not-terminated.txt +1 -0
  62. data/spec/acceptance/invalid/0005-strings/0002-single-quote.txt +1 -0
  63. data/spec/acceptance/invalid/0005-strings/0003-back-quote.txt +1 -0
  64. data/spec/acceptance/invalid/0005-strings/0004-carriage-return.txt +1 -0
  65. data/spec/acceptance/invalid/0005-strings/0005-line-feed.txt +2 -0
  66. data/spec/acceptance/invalid/0005-strings/0006-unknown-escape-a.txt +1 -0
  67. data/spec/acceptance/invalid/0005-strings/0007-unknown-escape-perl-style.txt +1 -0
  68. data/spec/acceptance/invalid/0005-strings/0008-unknown-escape-C-style.txt +1 -0
  69. data/spec/acceptance/invalid/0005-strings/0009-unknown-escape-ruby-style.txt +1 -0
  70. data/spec/acceptance/invalid/0005-strings/0010-escape-too-short.txt +1 -0
  71. data/spec/acceptance/invalid/0005-strings/0011-C-string-concat.txt +1 -0
  72. data/spec/acceptance/invalid/0005-strings/0012-perl-string-concat.txt +1 -0
  73. data/spec/acceptance/invalid/0005-strings/0013-Java-string-concat.txt +1 -0
  74. data/spec/acceptance/invalid/0006-encodings/0001-CESU-8.txt +1 -0
  75. data/spec/acceptance/invalid/0006-encodings/0002-Windows-31J.txt +1 -0
  76. data/spec/acceptance/invalid/0006-encodings/0003-EBCDIC.txt +1 -0
  77. data/spec/acceptance/invalid/0006-encodings/0004-overlong-utf8.txt +1 -0
  78. data/spec/acceptance/invalid/0007-arrays/0001-lacks-open.txt +1 -0
  79. data/spec/acceptance/invalid/0007-arrays/0002-lacks-close.txt +1 -0
  80. data/spec/acceptance/invalid/0007-arrays/0003-interleaving-parens.txt +1 -0
  81. data/spec/acceptance/invalid/0007-arrays/0004-dangling-comma.txt +1 -0
  82. data/spec/acceptance/invalid/0007-arrays/0005-missing-comma.txt +1 -0
  83. data/spec/acceptance/invalid/0007-arrays/0006-colon-instead-of-comma.txt +1 -0
  84. data/spec/acceptance/invalid/0008-hashes/0001-key-missing.txt +1 -0
  85. data/spec/acceptance/invalid/0008-hashes/0002-value-missing.txt +1 -0
  86. data/spec/acceptance/invalid/0008-hashes/0003-true-key.txt +1 -0
  87. data/spec/acceptance/invalid/0008-hashes/0004-false-key.txt +1 -0
  88. data/spec/acceptance/invalid/0008-hashes/0005-null-key.txt +1 -0
  89. data/spec/acceptance/invalid/0008-hashes/0006-numeric-key.txt +1 -0
  90. data/spec/acceptance/invalid/0008-hashes/0007-array-key.txt +1 -0
  91. data/spec/acceptance/invalid/0008-hashes/0008-hash-key.txt +1 -0
  92. data/spec/acceptance/invalid/0008-hashes/0009-key-not-escaped.txt +4 -0
  93. data/spec/acceptance/invalid/0009-javascriptisms/0001-JSONP.txt +1 -0
  94. data/spec/acceptance/invalid/0009-javascriptisms/0002-new-Array.txt +3 -0
  95. data/spec/acceptance/invalid/0009-javascriptisms/0003-new-Date.txt +1 -0
  96. data/spec/acceptance/invalid/0009-javascriptisms/0004-new-Error.txt +1 -0
  97. data/spec/acceptance/invalid/0009-javascriptisms/0005-Math.txt +1 -0
  98. data/spec/acceptance/invalid/0009-javascriptisms/0006-regular-expression.txt +1 -0
  99. data/spec/acceptance/invalid/0009-javascriptisms/0007-function.txt +7 -0
  100. data/spec/acceptance/invalid/0009-javascriptisms/0008-this.txt +1 -0
  101. data/spec/acceptance/invalid/0009-javascriptisms/0009-plusplus.txt +3 -0
  102. data/spec/acceptance/invalid/0009-javascriptisms/0010-ternary-operator.txt +1 -0
  103. data/spec/acceptance/valid/0001-ws/0001-space.json +1 -0
  104. data/spec/acceptance/valid/0001-ws/0002-tab.json +1 -0
  105. data/spec/acceptance/valid/0001-ws/0003-lf.json +1 -0
  106. data/spec/acceptance/valid/0001-ws/0004-cr.json +1 -0
  107. data/spec/acceptance/valid/0001-ws/0005-before.json +1 -0
  108. data/spec/acceptance/valid/0001-ws/0006-after.json +1 -0
  109. data/spec/acceptance/valid/0001-ws/0007-around-comma.json +3 -0
  110. data/spec/acceptance/valid/0001-ws/0008-around-colon.json +3 -0
  111. data/spec/acceptance/valid/0002-bare-values/0001-false.json +1 -0
  112. data/spec/acceptance/valid/0002-bare-values/0002-null.json +1 -0
  113. data/spec/acceptance/valid/0002-bare-values/0003-true.json +1 -0
  114. data/spec/acceptance/valid/0002-bare-values/0004-number.json +1 -0
  115. data/spec/acceptance/valid/0002-bare-values/0005-string.json +1 -0
  116. data/spec/acceptance/valid/0003-literals/0001-false.json +1 -0
  117. data/spec/acceptance/valid/0003-literals/0002-null.json +1 -0
  118. data/spec/acceptance/valid/0003-literals/0003-true.json +1 -0
  119. data/spec/acceptance/valid/0004-numbers/0000-zero.json +1 -0
  120. data/spec/acceptance/valid/0004-numbers/0001-one.json +1 -0
  121. data/spec/acceptance/valid/0004-numbers/0002-two.json +1 -0
  122. data/spec/acceptance/valid/0004-numbers/0003-three.json +1 -0
  123. data/spec/acceptance/valid/0004-numbers/0004-four.json +1 -0
  124. data/spec/acceptance/valid/0004-numbers/0005-five.json +1 -0
  125. data/spec/acceptance/valid/0004-numbers/0006-six.json +1 -0
  126. data/spec/acceptance/valid/0004-numbers/0007-seven.json +1 -0
  127. data/spec/acceptance/valid/0004-numbers/0008-eight.json +1 -0
  128. data/spec/acceptance/valid/0004-numbers/0009-nine.json +1 -0
  129. data/spec/acceptance/valid/0004-numbers/0010-ten.json +1 -0
  130. data/spec/acceptance/valid/0004-numbers/0011-minus.json +1 -0
  131. data/spec/acceptance/valid/0004-numbers/0012-fraction.json +1 -0
  132. data/spec/acceptance/valid/0004-numbers/0013-exponent.json +1 -0
  133. data/spec/acceptance/valid/0004-numbers/0014-exponent-minus.json +1 -0
  134. data/spec/acceptance/valid/0004-numbers/0015-exponent-plus.json +1 -0
  135. data/spec/acceptance/valid/0004-numbers/0016-complex.json +1 -0
  136. data/spec/acceptance/valid/0004-numbers/0017-DBL_MAX.json +1 -0
  137. data/spec/acceptance/valid/0004-numbers/0018-DBL_MIN.json +1 -0
  138. data/spec/acceptance/valid/0004-numbers/0019-subnormal-number.json +1 -0
  139. data/spec/acceptance/valid/0004-numbers/0020-1E400.json +1 -0
  140. data/spec/acceptance/valid/0004-numbers/0021-pi.json +1 -0
  141. data/spec/acceptance/valid/0004-numbers/0022-UINT32_MAX.json +1 -0
  142. data/spec/acceptance/valid/0004-numbers/0023-UINT64_MAX.json +1 -0
  143. data/spec/acceptance/valid/0004-numbers/0024-INT64_MIN.json +1 -0
  144. data/spec/acceptance/valid/0004-numbers/0025-high-resolution-zero.json +1 -0
  145. data/spec/acceptance/valid/0005-strings/0001-empty.json +1 -0
  146. data/spec/acceptance/valid/0005-strings/0002-basic-latin.json +1 -0
  147. data/spec/acceptance/valid/0005-strings/0003-escapes.json +1 -0
  148. data/spec/acceptance/valid/0005-strings/0004-raw-unicode.json +1 -0
  149. data/spec/acceptance/valid/0005-strings/0005-escaped-unicode.json +1 -0
  150. data/spec/acceptance/valid/0005-strings/0006-escaped-NUL.json +1 -0
  151. data/spec/acceptance/valid/0005-strings/0007-escaped-invalid-unicode-still-valid-as-json.json +1 -0
  152. data/spec/acceptance/valid/0005-strings/0008-ruby-json-gem-cant-handle-this.json +1 -0
  153. data/spec/acceptance/valid/0005-strings/0009-unescaped-invalid-javascript-still-valid-as-json.json +1 -0
  154. data/spec/acceptance/valid/0006-m17n/0001-genesis.json +6 -0
  155. data/spec/acceptance/valid/0006-m17n/0002-heart-sutra.json +5 -0
  156. data/spec/acceptance/valid/0006-m17n/0003-escaped-valid-surrogate-pair.json +1 -0
  157. data/spec/acceptance/valid/0006-m17n/0004-unescaped-valid-supplementary-multilingual-plane.json +1 -0
  158. data/spec/acceptance/valid/0007-arrays/0000-empty.json +1 -0
  159. data/spec/acceptance/valid/0007-arrays/0001-one-element.json +1 -0
  160. data/spec/acceptance/valid/0007-arrays/0002-multiple-elements.json +33 -0
  161. data/spec/acceptance/valid/0007-arrays/0003-various-types.json +1 -0
  162. data/spec/acceptance/valid/0007-arrays/0004-nested.json +17 -0
  163. data/spec/acceptance/valid/0008-hashes/0000-empty.json +1 -0
  164. data/spec/acceptance/valid/0008-hashes/0001-onekey.json +1 -0
  165. data/spec/acceptance/valid/0008-hashes/0002-many-keys.json +5 -0
  166. data/spec/acceptance/valid/0008-hashes/0003-empty-key.json +3 -0
  167. data/spec/acceptance/valid/0008-hashes/0004-true-value.json +3 -0
  168. data/spec/acceptance/valid/0008-hashes/0005-false-value.json +3 -0
  169. data/spec/acceptance/valid/0008-hashes/0006-null-value.json +3 -0
  170. data/spec/acceptance/valid/0008-hashes/0007-string-value.json +3 -0
  171. data/spec/acceptance/valid/0008-hashes/0008-numeric-value.json +3 -0
  172. data/spec/acceptance/valid/0008-hashes/0009-array-value.json +8 -0
  173. data/spec/acceptance/valid/0008-hashes/0010-hash-value.json +20 -0
  174. data/spec/acceptance/valid/0008-hashes/0011-duplicate-key-in-different-representations.json +4 -0
  175. data/spec/acceptance/valid/0008-hashes/0011-duplicate-key.json +4 -0
  176. data/spec/spec_helper.rb +54 -0
  177. metadata +520 -0
@@ -0,0 +1,66 @@
1
+ This directory contains various JSON and quasi-JSON texts. The files
2
+ under "valid" directory are believed to be valid JSON texts, while
3
+ those under "invalid" are believed to be invalid. And the author of
4
+ this library believe that there is no instance of text that exhibits
5
+ Russell's paradox -like behaviour, where one cannot say if that text
6
+ (if any) is valid or invalid.
7
+
8
+ All files under this directory, including this file itself, are
9
+ written by me, Urabe Shyouhei <shyouhei@ruby-lang.org>. You can
10
+ safely copy & paste them to your project to test your own JSON parser.
11
+
12
+ I repeat the license of this project below, just in case you separate
13
+ this test suite form the library.
14
+
15
+ ----------------------------------------------------------------------
16
+
17
+ Copyright (c) 2014 Urabe, Shyouhei. All rights reserved.
18
+
19
+ Redistribution and use in source and binary forms, with or without
20
+ modification, are permitted provided that the following conditions are
21
+ met:
22
+
23
+ - Redistributions of source code must retain the above copyright
24
+ notice, this list of conditions and the following disclaimer.
25
+
26
+ - Redistributions in binary form must reproduce the above copyright
27
+ notice, this list of conditions and the following disclaimer in
28
+ the documentation and/or other materials provided with the
29
+ distribution.
30
+
31
+ - Neither the name of Internet Society, IETF or IETF Trust, nor the
32
+ names of specific contributors, may be used to endorse or promote
33
+ products derived from this software without specific prior written
34
+ permission.
35
+
36
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37
+ “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47
+
48
+ ----------------------------------------------------------------------
49
+
50
+ P.S. For those who copy & paste the test cases to your own parser:
51
+
52
+ - In convenience for your own parser, most (not all) files starts
53
+ with '[' and ends with ']'. This is because that should also pass
54
+ older JSON spec (RFC4627).
55
+
56
+ - RFC7159 requests us, with using the strongest word (“MUST”) that
57
+ all the valid examples are to be accepted. On the other hand the
58
+ RFC _allows_ you to extend the grammar to, say, accept JavaScript
59
+ comments and so on. So failure in parsing valid examples are
60
+ fatal, but accepting invalid examples might not.
61
+
62
+ - RFC7159 tells no so much about semantics. For instance it does
63
+ not define object equality. It does not even define the character
64
+ set of parsed JSON strings (it DOES define the encoding of
65
+ generated JSON text themselves though).
66
+
@@ -0,0 +1 @@
1
+ ["Here you are U+0208 ->",
"<- (might be invisible in github) and is invalid"]
@@ -0,0 +1 @@
1
+ [/* comments are invalid in JSON */]
@@ -0,0 +1,2 @@
1
+ [// comments are invalid in JSON
2
+ ]
@@ -0,0 +1,2 @@
1
+ [# comments are invalid in JSON
2
+ ]
@@ -0,0 +1,3 @@
1
+ ["""
2
+ comments are invalid in JSON
3
+ """]
@@ -0,0 +1,2 @@
1
+ [-- comments are invalid in JSON
2
+ ]
@@ -0,0 +1,2 @@
1
+ [' comments are invalid in JSON
2
+ ]
@@ -0,0 +1 @@
1
+ {"1000000000":1,000,000,000}
@@ -0,0 +1 @@
1
+ ["������������������������������ ������������������"]
@@ -0,0 +1 @@
1
+ ["譐��̗����͔��{�ˉn�A�V���̖��N�A�Ⴍ���Ė����՞ԂɘA�ˁA�‚��ō]��тɕ₹��ꂽ���A���A�ĉ�A���眔�ޏ���������A�˗��ɊÂ񂸂�������Ƃ��Ȃ��‚�"]
@@ -0,0 +1 @@
1
+ ����k@����@薙���Z@�@����@���k@Ȗ����� %
@@ -0,0 +1 @@
1
+ ["����������������"]
@@ -0,0 +1 @@
1
+ ["Fiat lux": "Et facta est lux"]
@@ -0,0 +1 @@
1
+ {null:"defined?"}
@@ -0,0 +1 @@
1
+ callback({"JSONP":"is out of scope from JSON itself"});
@@ -0,0 +1,3 @@
1
+ {
2
+ "invalid": new Array(0)
3
+ }
@@ -0,0 +1 @@
1
+ [new Date(1981, 12, 20)]
@@ -0,0 +1,7 @@
1
+ {
2
+ "prototype": {
3
+ "init": function() {
4
+ alert("invalid");
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "Did you know this is valid in JS (but not in JSON)?" : "99"++
3
+ }
@@ -0,0 +1 @@
1
+ "Porro quisquam est, qui dolorem ipsum, quia dolor sit, amet, consectetur, adipisci velit."
@@ -0,0 +1 @@
1
+ [1.7976931348623157e+308]
@@ -0,0 +1 @@
1
+ [2.2250738585072014e-308]
@@ -0,0 +1 @@
1
+ [3.141592653589793238462643383279]
@@ -0,0 +1 @@
1
+ [18446744073709551615]