1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Bug fix and initial test-case infrastructure for control-character escaping

in the CLI.

FossilOrigin-Name: c809997792602a7299b8ab84d018a03d291695e308ce750fc8b9d7a824edfd6e
This commit is contained in:
drh
2025-02-24 13:27:16 +00:00
parent 21b431e685
commit 7db5e50b8d
4 changed files with 98 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
C Ongoing\swork\sto\sget\sall\sthe\squoting\sand\sescaping\svariations\sin\sthe\sCLI\nworking\scorrectly.
D 2025-02-24T12:41:30.706
C Bug\sfix\sand\sinitial\stest-case\sinfrastructure\sfor\scontrol-character\sescaping\nin\sthe\sCLI.
D 2025-02-24T13:27:16.805
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md e108e1e69ae8e8a59e93c455654b8ac9356a11720d3345df2a4743e9590fb20d
@@ -782,7 +782,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 626c24b258b111f75c22107aa5614ad89810df3026f5ca071116d3fe75925c75
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c a076f7db3a0fcbd9f710d7746cfc07e0b3baadee45eb3136bedc29c598ef8f1c
F src/shell.c.in 10182a36de8c86c90c59933d9d8a41657c34ecf4b80986d1e4f508c5d39f1cb8
F src/shell.c.in b6b9db1a32ac2befb2547d1cc6d35aacffdce20832a9ef19bc2cbd6d9c210365
F src/sqlite.h.in 8d4486fb28a90de818ac1e8c6206ea458e7de6bd8e0dfa3d554494f155be8c01
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@@ -1647,6 +1647,7 @@ F test/shell6.test e3b883b61d4916b6906678a35f9d19054861123ad91b856461e0a456273bd
F test/shell7.test 43fd8e511c533bab5232e95c7b4be93b243451709e89582600d4b6e67693d5c3
F test/shell8.test aea51ecbcd4494c746b096aeff51d841d04d5f0dc4b62eb42427f16109b87acd
F test/shell9.test 8742a5b390cdcef6369f5aa223e415aa4255a4129ef249b177887dc635a87209
F test/shellA.test e7ff53be62d79ade789ae1d3108109ece789af43c20e4340fb1a6155c9283b09
F test/shmlock.test 3dbf017d34ab0c60abe6a44e447d3552154bd0c87b41eaf5ceacd408dd13fda5
F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
F test/show_speedtest1_rtree.tcl 32e6c5f073d7426148a6936a0408f4b5b169aba5
@@ -2210,8 +2211,8 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 49a486c5069de041aedcbde4de178293e0463ae9918ecad7539eedf0ec77a139
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 14ff5557d450475ad959f8c753c0cecb85dfca7346fcacd91da16e4d36e30508
R 11c66d594c249e2c939f76c526b8b2e2
P b77aea93e7eff0af408f598727caedcfc4428361b8440fbc1cc54c18f93abb69
R 07a37e0204e0b2223ab24d63dd235850
U drh
Z 582aa1340d3741b95a01f42fe569eeff
Z 4fb627b379b6da581b9bfa45e4708891
# Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
b77aea93e7eff0af408f598727caedcfc4428361b8440fbc1cc54c18f93abb69
c809997792602a7299b8ab84d018a03d291695e308ce750fc8b9d7a824edfd6e

View File

@@ -1976,7 +1976,7 @@ static void output_quoted_string(ShellState *p, const char *zInX){
*/
static void output_quoted_escaped_string(ShellState *p, const char *z){
char *zEscaped;
sqlite3_fsetmode(out, _O_BINARY);
sqlite3_fsetmode(p->out, _O_BINARY);
if( p->eEscMode==SHELL_ESC_OFF ){
zEscaped = sqlite3_mprintf("%Q", z);
}else{

89
test/shellA.test Normal file
View File

@@ -0,0 +1,89 @@
# 2025-02-24
#
# 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.
#
#***********************************************************************
#
# Test cases for the command-line shell - focusing on .mode and
# especially control-character escaping and the --escape option.
#
# TESTRUNNER: shell
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set CLI [test_cli_invocation]
db close
forcedelete test.db test.db-journal test.db-wal
sqlite3 db test.db
do_execsql_test shellA-1.0 {
CREATE TABLE t1(a INT, x TEXT);
INSERT INTO t1 VALUES
(1, 'line with '' single quote'),
(2, concat(char(0x1b),'[31mVT-100 codes',char(0x1b),'[0m')),
(3, NULL),
(4, 1234),
(5, 568.25),
(6, unistr('new\u000aline')),
(7, unistr('carriage\u000dreturn')),
(8, 'last line');
} {}
# Initial verification that the database created correctly
# and that our calls to the CLI are working.
#
do_test shellA-1.2 {
exec $CLI test.db {.mode box} {SELECT * FROM t1;}
} {
┌───┬──────────────────────────┐
│ a │ x │
├───┼──────────────────────────┤
│ 1 │ line with ' single quote │
├───┼──────────────────────────┤
│ 2 │ ␛[31mVT-100 codes␛[0m │
├───┼──────────────────────────┤
│ 3 │ │
├───┼──────────────────────────┤
│ 4 │ 1234 │
├───┼──────────────────────────┤
│ 5 │ 568.25 │
├───┼──────────────────────────┤
│ 6 │ new │
│ │ line │
├───┼──────────────────────────┤
│ 7 │ carriage␍return │
├───┼──────────────────────────┤
│ 8 │ last line │
└───┴──────────────────────────┘
}
# Default output mode uses symbols for control characters
#
do_test shellA-1.3 {
exec $CLI test.db {SELECT x FROM t1 WHERE a=2;}
} {
␛[31mVT-100 codes␛[0m
}
do_test shellA-1.4 {
exec $CLI test.db --escape ascii {SELECT x FROM t1 WHERE a=2;}
} {
^[[31mVT-100 codes^[[0m
}
do_test shellA-1.5 {
exec $CLI test.db {.mode list --escape symbol} {SELECT x FROM t1 WHERE a=2;}
} {
␛[31mVT-100 codes␛[0m
}
do_test shellA-1.6 {
exec $CLI test.db {.mode list --escape ascii} {SELECT x FROM t1 WHERE a=2;}
} {
^[[31mVT-100 codes^[[0m
}
finish_test