/ Check-in [448d3ef6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Additional tests for malformed UTF-8. (CVS 4011)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 448d3ef670dce6d27c7d7b1be58088d45f8b6274
User & Date: drh 2007-05-15 18:35:21
Context
2007-05-16
11:55
Keep the full precision of integers if possible when casting to "numeric". Ticket #2364. (CVS 4012) check-in: 2ac985a3 user: drh tags: trunk
2007-05-15
18:35
Additional tests for malformed UTF-8. (CVS 4011) check-in: 448d3ef6 user: drh tags: trunk
16:51
Make sure pParse->rc gets set whenever sqlite3ErrorMsg() is called. This is added insurance that parsing will stop quickly after an error. This change did make the parser stop faster in some cases, which required some revisions to tests. (CVS 4010) check-in: f84d9dab user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added test/badutf.test.























































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# 2007 May 15
#
# The author disclaims copyright to this source code.  In place of
# a legal notice, here is a blessing:
#
#    May you do good and not evil.
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library. 
#
# This file checks to make sure SQLite is able to gracefully
# handle malformed UTF-8.
#
# $Id: badutf.test,v 1.1 2007/05/15 18:35:21 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

do_test badutf-1.1 {
  db eval {PRAGMA encoding=UTF8}
  sqlite3_exec db {SELECT hex('%80') AS x}
} {0 {x 80}}
do_test badutf-1.2 {
  sqlite3_exec db {SELECT hex('%81') AS x}
} {0 {x 81}}
do_test badutf-1.3 {
  sqlite3_exec db {SELECT hex('%bf') AS x}
} {0 {x BF}}
do_test badutf-1.4 {
  sqlite3_exec db {SELECT hex('%c0') AS x}
} {0 {x C0}}
do_test badutf-1.5 {
  sqlite3_exec db {SELECT hex('%e0') AS x}
} {0 {x E0}}
do_test badutf-1.6 {
  sqlite3_exec db {SELECT hex('%f0') AS x}
} {0 {x F0}}
do_test badutf-1.7 {
  sqlite3_exec db {SELECT hex('%ff') AS x}
} {0 {x FF}}

do_test badutf-1.10 {
  sqlite3 db2 {}
  db2 eval {PRAGMA encoding=UTF16be}
  sqlite3_exec db2 {SELECT hex('%80') AS x}
} {0 {x 0080}}
do_test badutf-1.11 {
  sqlite3_exec db2 {SELECT hex('%81') AS x}
} {0 {x 0081}}
do_test badutf-1.12 {
  sqlite3_exec db2 {SELECT hex('%bf') AS x}
} {0 {x 00BF}}
do_test badutf-1.13 {
  sqlite3_exec db2 {SELECT hex('%c0') AS x}
} {0 {x FFFD}}
do_test badutf-1.14 {
  sqlite3_exec db2 {SELECT hex('%c1') AS x}
} {0 {x FFFD}}
do_test badutf-1.15 {
  sqlite3_exec db2 {SELECT hex('%c0%bf') AS x}
} {0 {x FFFD}}
do_test badutf-1.16 {
  sqlite3_exec db2 {SELECT hex('%c1%bf') AS x}
} {0 {x FFFD}}
do_test badutf-1.17 {
  sqlite3_exec db2 {SELECT hex('%c3%bf') AS x}
} {0 {x 00FF}}
do_test badutf-1.18 {
  sqlite3_exec db2 {SELECT hex('%e0') AS x}
} {0 {x FFFD}}
do_test badutf-1.19 {
  sqlite3_exec db2 {SELECT hex('%f0') AS x}
} {0 {x FFFD}}
do_test badutf-1.20 {
  sqlite3_exec db2 {SELECT hex('%ff') AS x}
} {0 {x FFFD}}


do_test badutf-2.1 {
  sqlite3_exec db {SELECT '%80'=CAST(x'80' AS text) AS x}
} {0 {x 1}}
do_test badutf-2.2 {
  sqlite3_exec db {SELECT CAST('%80' AS blob)=x'80' AS x}
} {0 {x 1}}

do_test badutf-3.1 {
  sqlite3_exec db {SELECT length('%80') AS x}
} {0 {x 1}}
do_test badutf-3.2 {
  sqlite3_exec db {SELECT length('%61%62%63') AS x}
} {0 {x 3}}
do_test badutf-3.3 {
  sqlite3_exec db {SELECT length('%7f%80%81') AS x}
} {0 {x 3}}
do_test badutf-3.4 {
  sqlite3_exec db {SELECT length('%61%c0') AS x}
} {0 {x 2}}
do_test badutf-3.5 {
  sqlite3_exec db {SELECT length('%61%c0%80%80%80%80%80%80%80%80%80%80') AS x}
} {0 {x 2}}
do_test badutf-3.6 {
  sqlite3_exec db {SELECT length('%c0%80%80%80%80%80%80%80%80%80%80') AS x}
} {0 {x 1}}
do_test badutf-3.7 {
  sqlite3_exec db {SELECT length('%80%80%80%80%80%80%80%80%80%80') AS x}
} {0 {x 10}}
do_test badutf-3.8 {
  sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%80') AS x}
} {0 {x 6}}
do_test badutf-3.9 {
  sqlite3_exec db {SELECT length('%80%80%80%80%80%f0%80%80%80%ff') AS x}
} {0 {x 7}}

do_test badutf-4.1 {
  sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
} {0 {x F0}}
do_test badutf-4.2 {
  sqlite3_exec db {SELECT hex(ltrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
} {0 {x F0808080FF}}
do_test badutf-4.3 {
  sqlite3_exec db {SELECT hex(rtrim('%80%80%80%f0%80%80%80%ff','%80%ff')) AS x}
} {0 {x 808080F0}}
do_test badutf-4.4 {
  sqlite3_exec db {SELECT hex(trim('%80%80%80%f0%80%80%80%ff','%ff%80')) AS x}
} {0 {x 808080F0808080FF}}
do_test badutf-4.5 {
  sqlite3_exec db {SELECT hex(trim('%ff%80%80%f0%80%80%80%ff','%ff%80')) AS x}
} {0 {x 80F0808080FF}}
do_test badutf-4.6 {
  sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80')) AS x}
} {0 {x F0808080FF}}
do_test badutf-4.7 {
  sqlite3_exec db {SELECT hex(trim('%ff%80%f0%80%80%80%ff','%ff%80%80')) AS x}
} {0 {x FF80F0808080FF}}

db2 close
finish_test

Changes to test/func.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
323
324
325
326
327
328
329













330
331
332
333
334
335
336
337
338
339
340

341
342
343
344
345
346
347
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.66 2007/05/11 01:44:52 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a table to work with.
#
do_test func-0.0 {
................................................................................
# The "hex()" function was added in order to be able to render blobs
# generated by randomblob().  So this seems like a good place to test
# hex().
#
do_test func-9.10 {
  execsql {SELECT hex(x'00112233445566778899aAbBcCdDeEfF')}
} {00112233445566778899AABBCCDDEEFF}













do_test func-9.11 {
  execsql {SELECT hex(replace('abcdefg','ef','12'))}
} {61626364313267}
do_test func-9.12 {
  execsql {SELECT hex(replace('abcdefg','','12'))}
} {{}}
breakpoint
do_test func-9.13 {
  execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
} {616161616161626364656667}


# Use the "sqlite_register_test_function" TCL command which is part of
# the text fixture in order to verify correct operation of some of
# the user-defined SQL function APIs that are not used by the built-in
# functions.
#
set ::DB [sqlite3_connection_pointer db]
sqlite_register_test_function $::DB testfunc







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
|
|
>







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
...
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#    May you find forgiveness for yourself and forgive others.
#    May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.  The
# focus of this file is testing built-in functions.
#
# $Id: func.test,v 1.67 2007/05/15 18:35:21 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Create a table to work with.
#
do_test func-0.0 {
................................................................................
# The "hex()" function was added in order to be able to render blobs
# generated by randomblob().  So this seems like a good place to test
# hex().
#
do_test func-9.10 {
  execsql {SELECT hex(x'00112233445566778899aAbBcCdDeEfF')}
} {00112233445566778899AABBCCDDEEFF}
set encoding [db one {PRAGMA encoding}]
if {$encoding=="UTF-16le"} {
  do_test func-9.11-utf16le {
    execsql {SELECT hex(replace('abcdefg','ef','12'))}
  } {6100620063006400310032006700}
  do_test func-9.12-utf16le {
    execsql {SELECT hex(replace('abcdefg','','12'))}
  } {{}}
  breakpoint
  do_test func-9.13-utf16le {
    execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
  } {610061006100610061006100620063006400650066006700}
} elseif {$encoding=="UTF-8"} {
  do_test func-9.11-utf8 {
    execsql {SELECT hex(replace('abcdefg','ef','12'))}
  } {61626364313267}
  do_test func-9.12-utf8 {
    execsql {SELECT hex(replace('abcdefg','','12'))}
  } {{}}
  breakpoint
  do_test func-9.13-utf8 {
    execsql {SELECT hex(replace('aabcdefg','a','aaa'))}
  } {616161616161626364656667}
}
  
# Use the "sqlite_register_test_function" TCL command which is part of
# the text fixture in order to verify correct operation of some of
# the user-defined SQL function APIs that are not used by the built-in
# functions.
#
set ::DB [sqlite3_connection_pointer db]
sqlite_register_test_function $::DB testfunc