jsonpath_encoding.out 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. --
  2. -- encoding-sensitive tests for jsonpath
  3. --
  4. -- We provide expected-results files for UTF8 (jsonpath_encoding.out)
  5. -- and for SQL_ASCII (jsonpath_encoding_1.out). Skip otherwise.
  6. SELECT getdatabaseencoding() NOT IN ('UTF8', 'SQL_ASCII')
  7. AS skip_test \gset
  8. \if :skip_test
  9. \quit
  10. \endif
  11. SELECT getdatabaseencoding(); -- just to label the results files
  12. getdatabaseencoding
  13. ---------------------
  14. UTF8
  15. (1 row)
  16. -- checks for double-quoted values
  17. -- basic unicode input
  18. SELECT '"\u"'::jsonpath; -- ERROR, incomplete escape
  19. ERROR: invalid unicode sequence at or near "\u" of jsonpath input
  20. LINE 1: SELECT '"\u"'::jsonpath;
  21. ^
  22. SELECT '"\u00"'::jsonpath; -- ERROR, incomplete escape
  23. ERROR: invalid unicode sequence at or near "\u00" of jsonpath input
  24. LINE 1: SELECT '"\u00"'::jsonpath;
  25. ^
  26. SELECT '"\u000g"'::jsonpath; -- ERROR, g is not a hex digit
  27. ERROR: invalid unicode sequence at or near "\u000" of jsonpath input
  28. LINE 1: SELECT '"\u000g"'::jsonpath;
  29. ^
  30. SELECT '"\u0000"'::jsonpath; -- OK, legal escape
  31. ERROR: unsupported Unicode escape sequence
  32. LINE 1: SELECT '"\u0000"'::jsonpath;
  33. ^
  34. DETAIL: \u0000 cannot be converted to text.
  35. SELECT '"\uaBcD"'::jsonpath; -- OK, uppercase and lower case both OK
  36. jsonpath
  37. ----------
  38. "ꯍ"
  39. (1 row)
  40. -- handling of unicode surrogate pairs
  41. select '"\ud83d\ude04\ud83d\udc36"'::jsonpath as correct_in_utf8;
  42. correct_in_utf8
  43. -----------------
  44. "😄🐶"
  45. (1 row)
  46. select '"\ud83d\ud83d"'::jsonpath; -- 2 high surrogates in a row
  47. ERROR: invalid input syntax for type jsonpath
  48. LINE 1: select '"\ud83d\ud83d"'::jsonpath;
  49. ^
  50. DETAIL: Unicode high surrogate must not follow a high surrogate.
  51. select '"\ude04\ud83d"'::jsonpath; -- surrogates in wrong order
  52. ERROR: invalid input syntax for type jsonpath
  53. LINE 1: select '"\ude04\ud83d"'::jsonpath;
  54. ^
  55. DETAIL: Unicode low surrogate must follow a high surrogate.
  56. select '"\ud83dX"'::jsonpath; -- orphan high surrogate
  57. ERROR: invalid input syntax for type jsonpath
  58. LINE 1: select '"\ud83dX"'::jsonpath;
  59. ^
  60. DETAIL: Unicode low surrogate must follow a high surrogate.
  61. select '"\ude04X"'::jsonpath; -- orphan low surrogate
  62. ERROR: invalid input syntax for type jsonpath
  63. LINE 1: select '"\ude04X"'::jsonpath;
  64. ^
  65. DETAIL: Unicode low surrogate must follow a high surrogate.
  66. --handling of simple unicode escapes
  67. select '"the Copyright \u00a9 sign"'::jsonpath as correct_in_utf8;
  68. correct_in_utf8
  69. ------------------------
  70. "the Copyright © sign"
  71. (1 row)
  72. select '"dollar \u0024 character"'::jsonpath as correct_everywhere;
  73. correct_everywhere
  74. ----------------------
  75. "dollar $ character"
  76. (1 row)
  77. select '"dollar \\u0024 character"'::jsonpath as not_an_escape;
  78. not_an_escape
  79. ----------------------------
  80. "dollar \\u0024 character"
  81. (1 row)
  82. select '"null \u0000 escape"'::jsonpath as not_unescaped;
  83. ERROR: unsupported Unicode escape sequence
  84. LINE 1: select '"null \u0000 escape"'::jsonpath as not_unescaped;
  85. ^
  86. DETAIL: \u0000 cannot be converted to text.
  87. select '"null \\u0000 escape"'::jsonpath as not_an_escape;
  88. not_an_escape
  89. -----------------------
  90. "null \\u0000 escape"
  91. (1 row)
  92. -- checks for quoted key names
  93. -- basic unicode input
  94. SELECT '$."\u"'::jsonpath; -- ERROR, incomplete escape
  95. ERROR: invalid unicode sequence at or near "\u" of jsonpath input
  96. LINE 1: SELECT '$."\u"'::jsonpath;
  97. ^
  98. SELECT '$."\u00"'::jsonpath; -- ERROR, incomplete escape
  99. ERROR: invalid unicode sequence at or near "\u00" of jsonpath input
  100. LINE 1: SELECT '$."\u00"'::jsonpath;
  101. ^
  102. SELECT '$."\u000g"'::jsonpath; -- ERROR, g is not a hex digit
  103. ERROR: invalid unicode sequence at or near "\u000" of jsonpath input
  104. LINE 1: SELECT '$."\u000g"'::jsonpath;
  105. ^
  106. SELECT '$."\u0000"'::jsonpath; -- OK, legal escape
  107. ERROR: unsupported Unicode escape sequence
  108. LINE 1: SELECT '$."\u0000"'::jsonpath;
  109. ^
  110. DETAIL: \u0000 cannot be converted to text.
  111. SELECT '$."\uaBcD"'::jsonpath; -- OK, uppercase and lower case both OK
  112. jsonpath
  113. ----------
  114. $."ꯍ"
  115. (1 row)
  116. -- handling of unicode surrogate pairs
  117. select '$."\ud83d\ude04\ud83d\udc36"'::jsonpath as correct_in_utf8;
  118. correct_in_utf8
  119. -----------------
  120. $."😄🐶"
  121. (1 row)
  122. select '$."\ud83d\ud83d"'::jsonpath; -- 2 high surrogates in a row
  123. ERROR: invalid input syntax for type jsonpath
  124. LINE 1: select '$."\ud83d\ud83d"'::jsonpath;
  125. ^
  126. DETAIL: Unicode high surrogate must not follow a high surrogate.
  127. select '$."\ude04\ud83d"'::jsonpath; -- surrogates in wrong order
  128. ERROR: invalid input syntax for type jsonpath
  129. LINE 1: select '$."\ude04\ud83d"'::jsonpath;
  130. ^
  131. DETAIL: Unicode low surrogate must follow a high surrogate.
  132. select '$."\ud83dX"'::jsonpath; -- orphan high surrogate
  133. ERROR: invalid input syntax for type jsonpath
  134. LINE 1: select '$."\ud83dX"'::jsonpath;
  135. ^
  136. DETAIL: Unicode low surrogate must follow a high surrogate.
  137. select '$."\ude04X"'::jsonpath; -- orphan low surrogate
  138. ERROR: invalid input syntax for type jsonpath
  139. LINE 1: select '$."\ude04X"'::jsonpath;
  140. ^
  141. DETAIL: Unicode low surrogate must follow a high surrogate.
  142. --handling of simple unicode escapes
  143. select '$."the Copyright \u00a9 sign"'::jsonpath as correct_in_utf8;
  144. correct_in_utf8
  145. --------------------------
  146. $."the Copyright © sign"
  147. (1 row)
  148. select '$."dollar \u0024 character"'::jsonpath as correct_everywhere;
  149. correct_everywhere
  150. ------------------------
  151. $."dollar $ character"
  152. (1 row)
  153. select '$."dollar \\u0024 character"'::jsonpath as not_an_escape;
  154. not_an_escape
  155. ------------------------------
  156. $."dollar \\u0024 character"
  157. (1 row)
  158. select '$."null \u0000 escape"'::jsonpath as not_unescaped;
  159. ERROR: unsupported Unicode escape sequence
  160. LINE 1: select '$."null \u0000 escape"'::jsonpath as not_unescaped;
  161. ^
  162. DETAIL: \u0000 cannot be converted to text.
  163. select '$."null \\u0000 escape"'::jsonpath as not_an_escape;
  164. not_an_escape
  165. -------------------------
  166. $."null \\u0000 escape"
  167. (1 row)