From 67fabccb3d71a4776d3b4d248cba9aa497c8aa29 Mon Sep 17 00:00:00 2001 From: George Hansper Date: Tue, 26 Mar 2024 20:23:27 +1100 Subject: [PATCH] Added tests around embedded quotes to tests/test-augtool/quoted-strings.sh (#826) --- tests/root/var/tmp/test-quoted-strings.txt | 2 + tests/test-augtool/quoted-strings.sh | 82 +++++++++++++++++++--- 2 files changed, 73 insertions(+), 11 deletions(-) diff --git a/tests/root/var/tmp/test-quoted-strings.txt b/tests/root/var/tmp/test-quoted-strings.txt index a9b378e1..c39c8afb 100644 --- a/tests/root/var/tmp/test-quoted-strings.txt +++ b/tests/root/var/tmp/test-quoted-strings.txt @@ -1 +1,3 @@ find this: ]][ )( . * $ / \ +find simple quotes: '"\ +--- original end of file --- diff --git a/tests/test-augtool/quoted-strings.sh b/tests/test-augtool/quoted-strings.sh index 5a71e94b..98cf7c5e 100644 --- a/tests/test-augtool/quoted-strings.sh +++ b/tests/test-augtool/quoted-strings.sh @@ -1,6 +1,37 @@ #!/bin/bash -commands=" +#refresh=1 +#echo=1 +# Notes on quoting in augtool, and augrun +# (does not apply to augset, augmatch etc because they do not rely on augrun to tokenize a command-line) +# shell-style quoting rules apply, eg +# augtool value +# "a b" -> a b +# "a"b -> ab +# a" "b -> a b +# "'" -> ' +# '"' -> " +# '\'' -> ' +# '\"' -> \" +# "\"" -> " +# "\'" -> \' +# "\\" -> \ +# \a -> unknown escape sequence +# "\a" -> unknown escape sequence +# Except +# "a\ b" -> a b +# "a\tb" -> a b (ie tab) +# "a\nb" -> a(newline)b +# "a\\b" -> a\b +# +# This file is confusing because bash does additional backslash-quote substitutions, too. Sorry +# Using read ...<<\EOF because bash does not do any interpretion of quotes in this region +# note that within the <<\EOF ... EOF region +# \\ -> \ +# \\\\ -> \\ +# and when a \ is the last char of the line, it needs to be \\ to avoid escaping the trailing newline +# this applies to comments, too +read -d '' commands <<\EOF set /files/var/tmp/test-quoted-strings.txt/01 '[' set /files/var/tmp/test-quoted-strings.txt/02 ']' set /files/var/tmp/test-quoted-strings.txt/03 '][' @@ -9,21 +40,43 @@ set /files/var/tmp/test-quoted-strings.txt/05 '[][' set /files/var/tmp/test-quoted-strings.txt/06 '[]]' set /files/var/tmp/test-quoted-strings.txt/07 '(' set /files/var/tmp/test-quoted-strings.txt/08 ')' -set /files/var/tmp/test-quoted-strings.txt/09 '"\""' -insert 010 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\]\]\[ \)\( .*')] -set /files/var/tmp/test-quoted-strings.txt/010 'found ]][ )(' -insert 011 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\\\\..*')] -set /files/var/tmp/test-quoted-strings.txt/011 'found .' -" +# value is one double-quote +set /files/var/tmp/test-quoted-strings.txt/09 '"' +# value is one single-quote +set /files/var/tmp/test-quoted-strings.txt/10 "'" +# value is one back-slash +set /files/var/tmp/test-quoted-strings.txt/11 '\\\\' +set /files/var/tmp/test-quoted-strings.txt/12 '-- nothing should appear after this line --' +insert 001 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\\]\\]\\[ \\)\\( .*')] +set /files/var/tmp/test-quoted-strings.txt/001 'found ]][ )(' +insert 002 after /files/var/tmp/test-quoted-strings.txt/seq::*[.=~regexp('.*\\\\..*')] +set /files/var/tmp/test-quoted-strings.txt/002 'found .' +# Find the line which is '"\\ +insert 003 after /files/var/tmp/test-quoted-strings.txt/seq::*[.="find simple quotes: '" + '"\\\\'] +set /files/var/tmp/test-quoted-strings.txt/003 "found '"'"\\\\' +# Find the line which is just one double-quote +insert 091 after "/files/var/tmp/test-quoted-strings.txt/seq::*[.='"']" +set /files/var/tmp/test-quoted-strings.txt/091 'found single-quoted " in quoted path' +# Find the line which is just one single-quote +insert 101 after "/files/var/tmp/test-quoted-strings.txt/seq::*[.="'"]" +set /files/var/tmp/test-quoted-strings.txt/101 "found double-quoted ' in quoted path" +# Find the line which is just one back-slash +insert 111 after "/files/var/tmp/test-quoted-strings.txt/seq::*[.="\\\\"]" +set /files/var/tmp/test-quoted-strings.txt/111 'found double-quoted \\\\ in quoted path' +EOF lens=Simplelines.lns file="/var/tmp/test-quoted-strings.txt" -diff='--- /var/tmp/test-quoted-strings.txt +read -d '' diff <<\EOF +--- /var/tmp/test-quoted-strings.txt +++ /var/tmp/test-quoted-strings.txt.augnew -@@ -1 +1,12 @@ - find this: ]][ )( . * $ / \ +@@ -1,3 +1,21 @@ + find this: ]][ )( . * $ / \\ +found . +found ]][ )( + find simple quotes: '"\\ ++found '"\\ + --- original end of file --- +[ +] +][ @@ -32,4 +85,11 @@ diff='--- /var/tmp/test-quoted-strings.txt +[]] +( +) -+"' ++" ++found single-quoted " in quoted path ++' ++found double-quoted ' in quoted path ++\\ ++found double-quoted \\ in quoted path ++-- nothing should appear after this line -- +EOF