]> granicus.if.org Git - postgresql/blob - src/test/regress/expected/json_encoding.out
Don't allow logging in with empty password.
[postgresql] / src / test / regress / expected / json_encoding.out
1 -- encoding-sensitive tests for json and jsonb
2 -- first json
3 -- basic unicode input
4 SELECT '"\u"'::json;                    -- ERROR, incomplete escape
5 ERROR:  invalid input syntax for type json
6 LINE 1: SELECT '"\u"'::json;
7                ^
8 DETAIL:  "\u" must be followed by four hexadecimal digits.
9 CONTEXT:  JSON data, line 1: "\u"
10 SELECT '"\u00"'::json;                  -- ERROR, incomplete escape
11 ERROR:  invalid input syntax for type json
12 LINE 1: SELECT '"\u00"'::json;
13                ^
14 DETAIL:  "\u" must be followed by four hexadecimal digits.
15 CONTEXT:  JSON data, line 1: "\u00"
16 SELECT '"\u000g"'::json;                -- ERROR, g is not a hex digit
17 ERROR:  invalid input syntax for type json
18 LINE 1: SELECT '"\u000g"'::json;
19                ^
20 DETAIL:  "\u" must be followed by four hexadecimal digits.
21 CONTEXT:  JSON data, line 1: "\u000g...
22 SELECT '"\u0000"'::json;                -- OK, legal escape
23    json   
24 ----------
25  "\u0000"
26 (1 row)
27
28 SELECT '"\uaBcD"'::json;                -- OK, uppercase and lower case both OK
29    json   
30 ----------
31  "\uaBcD"
32 (1 row)
33
34 -- handling of unicode surrogate pairs
35 select json '{ "a":  "\ud83d\ude04\ud83d\udc36" }' -> 'a' as correct_in_utf8;
36       correct_in_utf8       
37 ----------------------------
38  "\ud83d\ude04\ud83d\udc36"
39 (1 row)
40
41 select json '{ "a":  "\ud83d\ud83d" }' -> 'a'; -- 2 high surrogates in a row
42 ERROR:  invalid input syntax for type json
43 DETAIL:  Unicode high surrogate must not follow a high surrogate.
44 CONTEXT:  JSON data, line 1: { "a":...
45 select json '{ "a":  "\ude04\ud83d" }' -> 'a'; -- surrogates in wrong order
46 ERROR:  invalid input syntax for type json
47 DETAIL:  Unicode low surrogate must follow a high surrogate.
48 CONTEXT:  JSON data, line 1: { "a":...
49 select json '{ "a":  "\ud83dX" }' -> 'a'; -- orphan high surrogate
50 ERROR:  invalid input syntax for type json
51 DETAIL:  Unicode low surrogate must follow a high surrogate.
52 CONTEXT:  JSON data, line 1: { "a":...
53 select json '{ "a":  "\ude04X" }' -> 'a'; -- orphan low surrogate
54 ERROR:  invalid input syntax for type json
55 DETAIL:  Unicode low surrogate must follow a high surrogate.
56 CONTEXT:  JSON data, line 1: { "a":...
57 --handling of simple unicode escapes
58 select json '{ "a":  "the Copyright \u00a9 sign" }' as correct_in_utf8;
59             correct_in_utf8            
60 ---------------------------------------
61  { "a":  "the Copyright \u00a9 sign" }
62 (1 row)
63
64 select json '{ "a":  "dollar \u0024 character" }' as correct_everywhere;
65          correct_everywhere          
66 -------------------------------------
67  { "a":  "dollar \u0024 character" }
68 (1 row)
69
70 select json '{ "a":  "dollar \\u0024 character" }' as not_an_escape;
71             not_an_escape             
72 --------------------------------------
73  { "a":  "dollar \\u0024 character" }
74 (1 row)
75
76 select json '{ "a":  "null \u0000 escape" }' as not_unescaped;
77          not_unescaped          
78 --------------------------------
79  { "a":  "null \u0000 escape" }
80 (1 row)
81
82 select json '{ "a":  "null \\u0000 escape" }' as not_an_escape;
83           not_an_escape          
84 ---------------------------------
85  { "a":  "null \\u0000 escape" }
86 (1 row)
87
88 select json '{ "a":  "the Copyright \u00a9 sign" }' ->> 'a' as correct_in_utf8;
89    correct_in_utf8    
90 ----------------------
91  the Copyright © sign
92 (1 row)
93
94 select json '{ "a":  "dollar \u0024 character" }' ->> 'a' as correct_everywhere;
95  correct_everywhere 
96 --------------------
97  dollar $ character
98 (1 row)
99
100 select json '{ "a":  "dollar \\u0024 character" }' ->> 'a' as not_an_escape;
101       not_an_escape      
102 -------------------------
103  dollar \u0024 character
104 (1 row)
105
106 select json '{ "a":  "null \u0000 escape" }' ->> 'a' as fails;
107 ERROR:  unsupported Unicode escape sequence
108 DETAIL:  \u0000 cannot be converted to text.
109 CONTEXT:  JSON data, line 1: { "a":...
110 select json '{ "a":  "null \\u0000 escape" }' ->> 'a' as not_an_escape;
111    not_an_escape    
112 --------------------
113  null \u0000 escape
114 (1 row)
115
116 -- then jsonb
117 -- basic unicode input
118 SELECT '"\u"'::jsonb;                   -- ERROR, incomplete escape
119 ERROR:  invalid input syntax for type json
120 LINE 1: SELECT '"\u"'::jsonb;
121                ^
122 DETAIL:  "\u" must be followed by four hexadecimal digits.
123 CONTEXT:  JSON data, line 1: "\u"
124 SELECT '"\u00"'::jsonb;                 -- ERROR, incomplete escape
125 ERROR:  invalid input syntax for type json
126 LINE 1: SELECT '"\u00"'::jsonb;
127                ^
128 DETAIL:  "\u" must be followed by four hexadecimal digits.
129 CONTEXT:  JSON data, line 1: "\u00"
130 SELECT '"\u000g"'::jsonb;               -- ERROR, g is not a hex digit
131 ERROR:  invalid input syntax for type json
132 LINE 1: SELECT '"\u000g"'::jsonb;
133                ^
134 DETAIL:  "\u" must be followed by four hexadecimal digits.
135 CONTEXT:  JSON data, line 1: "\u000g...
136 SELECT '"\u0045"'::jsonb;               -- OK, legal escape
137  jsonb 
138 -------
139  "E"
140 (1 row)
141
142 SELECT '"\u0000"'::jsonb;               -- ERROR, we don't support U+0000
143 ERROR:  unsupported Unicode escape sequence
144 LINE 1: SELECT '"\u0000"'::jsonb;
145                ^
146 DETAIL:  \u0000 cannot be converted to text.
147 CONTEXT:  JSON data, line 1: ...
148 -- use octet_length here so we don't get an odd unicode char in the
149 -- output
150 SELECT octet_length('"\uaBcD"'::jsonb::text); -- OK, uppercase and lower case both OK
151  octet_length 
152 --------------
153             5
154 (1 row)
155
156 -- handling of unicode surrogate pairs
157 SELECT octet_length((jsonb '{ "a":  "\ud83d\ude04\ud83d\udc36" }' -> 'a')::text) AS correct_in_utf8;
158  correct_in_utf8 
159 -----------------
160               10
161 (1 row)
162
163 SELECT jsonb '{ "a":  "\ud83d\ud83d" }' -> 'a'; -- 2 high surrogates in a row
164 ERROR:  invalid input syntax for type json
165 LINE 1: SELECT jsonb '{ "a":  "\ud83d\ud83d" }' -> 'a';
166                      ^
167 DETAIL:  Unicode high surrogate must not follow a high surrogate.
168 CONTEXT:  JSON data, line 1: { "a":...
169 SELECT jsonb '{ "a":  "\ude04\ud83d" }' -> 'a'; -- surrogates in wrong order
170 ERROR:  invalid input syntax for type json
171 LINE 1: SELECT jsonb '{ "a":  "\ude04\ud83d" }' -> 'a';
172                      ^
173 DETAIL:  Unicode low surrogate must follow a high surrogate.
174 CONTEXT:  JSON data, line 1: { "a":...
175 SELECT jsonb '{ "a":  "\ud83dX" }' -> 'a'; -- orphan high surrogate
176 ERROR:  invalid input syntax for type json
177 LINE 1: SELECT jsonb '{ "a":  "\ud83dX" }' -> 'a';
178                      ^
179 DETAIL:  Unicode low surrogate must follow a high surrogate.
180 CONTEXT:  JSON data, line 1: { "a":...
181 SELECT jsonb '{ "a":  "\ude04X" }' -> 'a'; -- orphan low surrogate
182 ERROR:  invalid input syntax for type json
183 LINE 1: SELECT jsonb '{ "a":  "\ude04X" }' -> 'a';
184                      ^
185 DETAIL:  Unicode low surrogate must follow a high surrogate.
186 CONTEXT:  JSON data, line 1: { "a":...
187 -- handling of simple unicode escapes
188 SELECT jsonb '{ "a":  "the Copyright \u00a9 sign" }' as correct_in_utf8;
189         correct_in_utf8        
190 -------------------------------
191  {"a": "the Copyright © sign"}
192 (1 row)
193
194 SELECT jsonb '{ "a":  "dollar \u0024 character" }' as correct_everywhere;
195      correct_everywhere      
196 -----------------------------
197  {"a": "dollar $ character"}
198 (1 row)
199
200 SELECT jsonb '{ "a":  "dollar \\u0024 character" }' as not_an_escape;
201            not_an_escape           
202 -----------------------------------
203  {"a": "dollar \\u0024 character"}
204 (1 row)
205
206 SELECT jsonb '{ "a":  "null \u0000 escape" }' as fails;
207 ERROR:  unsupported Unicode escape sequence
208 LINE 1: SELECT jsonb '{ "a":  "null \u0000 escape" }' as fails;
209                      ^
210 DETAIL:  \u0000 cannot be converted to text.
211 CONTEXT:  JSON data, line 1: { "a":...
212 SELECT jsonb '{ "a":  "null \\u0000 escape" }' as not_an_escape;
213         not_an_escape         
214 ------------------------------
215  {"a": "null \\u0000 escape"}
216 (1 row)
217
218 SELECT jsonb '{ "a":  "the Copyright \u00a9 sign" }' ->> 'a' as correct_in_utf8;
219    correct_in_utf8    
220 ----------------------
221  the Copyright © sign
222 (1 row)
223
224 SELECT jsonb '{ "a":  "dollar \u0024 character" }' ->> 'a' as correct_everywhere;
225  correct_everywhere 
226 --------------------
227  dollar $ character
228 (1 row)
229
230 SELECT jsonb '{ "a":  "dollar \\u0024 character" }' ->> 'a' as not_an_escape;
231       not_an_escape      
232 -------------------------
233  dollar \u0024 character
234 (1 row)
235
236 SELECT jsonb '{ "a":  "null \u0000 escape" }' ->> 'a' as fails;
237 ERROR:  unsupported Unicode escape sequence
238 LINE 1: SELECT jsonb '{ "a":  "null \u0000 escape" }' ->> 'a' as fai...
239                      ^
240 DETAIL:  \u0000 cannot be converted to text.
241 CONTEXT:  JSON data, line 1: { "a":...
242 SELECT jsonb '{ "a":  "null \\u0000 escape" }' ->> 'a' as not_an_escape;
243    not_an_escape    
244 --------------------
245  null \u0000 escape
246 (1 row)
247