@@ -252,3 +252,42 @@ func TestFormatBinaryDateTime(t *testing.T) {
252
252
expect ("1978-12-30 15:46:23" , 7 , 19 )
253
253
expect ("1978-12-30 15:46:23.987654" , 11 , 26 )
254
254
}
255
+
256
+ func TestEscapeString (t * testing.T ) {
257
+ expect := func (expected , value string ) {
258
+ actual := string (EscapeString ([]byte (value )))
259
+ if actual != expected {
260
+ t .Errorf (
261
+ "expected %s, got %s" ,
262
+ expected , actual ,
263
+ )
264
+ }
265
+ }
266
+
267
+ expect ("foo\\ 0bar" , "foo\x00 bar" )
268
+ expect ("foo\\ nbar" , "foo\n bar" )
269
+ expect ("foo\\ rbar" , "foo\r bar" )
270
+ expect ("foo\\ Zbar" , "foo\x1a bar" )
271
+ expect ("foo\\ \" bar" , "foo\" bar" )
272
+ expect ("foo\\ \\ bar" , "foo\\ bar" )
273
+ expect ("foo\\ 'bar" , "foo'bar" )
274
+ }
275
+
276
+ func TestEscapeQuotes (t * testing.T ) {
277
+ expect := func (expected , value string ) {
278
+ actual := string (EscapeQuotes ([]byte (value )))
279
+ if actual != expected {
280
+ t .Errorf (
281
+ "expected %s, got %s" ,
282
+ expected , actual ,
283
+ )
284
+ }
285
+ }
286
+
287
+ expect ("foo\x00 bar" , "foo\x00 bar" ) // not affected
288
+ expect ("foo\n bar" , "foo\n bar" ) // not affected
289
+ expect ("foo\r bar" , "foo\r bar" ) // not affected
290
+ expect ("foo\x1a bar" , "foo\x1a bar" ) // not affected
291
+ expect ("foo''bar" , "foo'bar" ) // affected
292
+ expect ("foo\" bar" , "foo\" bar" ) // not affected
293
+ }
0 commit comments