Root/
| 1 | #!/bin/bash |
| 2 | . ./Common |
| 3 | |
| 4 | # |
| 5 | # Note that we have to escape things for the shell as well. In general, |
| 6 | # for any character C, \C becomes C. However, in the case of <<EOF ... EOF, |
| 7 | # \ is left as is if it doesn't precede a special character. |
| 8 | # |
| 9 | |
| 10 | ############################################################################### |
| 11 | |
| 12 | tst "substitutions: escape x in regexp" -R '*\\x' <<EOF |
| 13 | EOF |
| 14 | |
| 15 | expect <<EOF |
| 16 | ^.*\\x\$ |
| 17 | EOF |
| 18 | |
| 19 | #------------------------------------------------------------------------------ |
| 20 | tst "substitutions: escape * in regexp" -R '*\\*' <<EOF |
| 21 | EOF |
| 22 | |
| 23 | expect <<EOF |
| 24 | ^.*\*\$ |
| 25 | EOF |
| 26 | |
| 27 | #------------------------------------------------------------------------------ |
| 28 | |
| 29 | tst "substitutions: escape . in regexp (implicit)" -R 'x.y' <<EOF |
| 30 | EOF |
| 31 | |
| 32 | expect <<EOF |
| 33 | ^x\.y\$ |
| 34 | EOF |
| 35 | |
| 36 | #------------------------------------------------------------------------------ |
| 37 | |
| 38 | tst "substitutions: escape | in regexp" -R 'a\\\|b' <<EOF |
| 39 | EOF |
| 40 | |
| 41 | expect <<EOF |
| 42 | ^a\\|b\$ |
| 43 | EOF |
| 44 | |
| 45 | #------------------------------------------------------------------------------ |
| 46 | |
| 47 | tst "substitutions: escape \\ in regexp" -R 'x\\\\y' <<EOF |
| 48 | EOF |
| 49 | |
| 50 | expect <<EOF |
| 51 | ^x\\\\y\$ |
| 52 | EOF |
| 53 | |
| 54 | #------------------------------------------------------------------------------ |
| 55 | |
| 56 | tst_fail "substitutions: try to escape EOL in regexp" -R 'x\\' <<EOF |
| 57 | EOF |
| 58 | |
| 59 | expect <<EOF |
| 60 | dummy:2: regexp ends with backslash |
| 61 | EOF |
| 62 | |
| 63 | #------------------------------------------------------------------------------ |
| 64 | |
| 65 | tst "substitutions: escape space in regexp (match)" -q '"x=a c"' <<EOF |
| 66 | !-s |
| 67 | y=a |
| 68 | x=a\ c { y=b } |
| 69 | EOF |
| 70 | |
| 71 | expect <<EOF |
| 72 | y=b |
| 73 | EOF |
| 74 | |
| 75 | #------------------------------------------------------------------------------ |
| 76 | |
| 77 | tst "substitutions: escape space in regexp (no match)" -q '"x=a b"' <<EOF |
| 78 | !-s |
| 79 | y=a |
| 80 | x=a\ c { y=b } |
| 81 | EOF |
| 82 | |
| 83 | expect <<EOF |
| 84 | y=a |
| 85 | EOF |
| 86 | |
| 87 | #------------------------------------------------------------------------------ |
| 88 | |
| 89 | tst "substitutions: escape \$ in value" -q <<EOF |
| 90 | !-s |
| 91 | x=y\\$ |
| 92 | EOF |
| 93 | |
| 94 | expect <<EOF |
| 95 | x=y\$ |
| 96 | EOF |
| 97 | |
| 98 | #------------------------------------------------------------------------------ |
| 99 | |
| 100 | tst "substitutions: escape x in value" -q <<EOF |
| 101 | !-s |
| 102 | x=y\x |
| 103 | EOF |
| 104 | |
| 105 | expect <<EOF |
| 106 | x=yx |
| 107 | EOF |
| 108 | |
| 109 | #------------------------------------------------------------------------------ |
| 110 | |
| 111 | tst "substitutions: escape space in value" -q <<EOF |
| 112 | !-s |
| 113 | x=x\ y |
| 114 | EOF |
| 115 | |
| 116 | expect <<EOF |
| 117 | x=x y |
| 118 | EOF |
| 119 | |
| 120 | #------------------------------------------------------------------------------ |
| 121 | |
| 122 | tst "substitutions: escape \\ in value" -q <<EOF |
| 123 | !-s |
| 124 | x=a\\\\b |
| 125 | EOF |
| 126 | |
| 127 | expect <<EOF |
| 128 | x=a\\b |
| 129 | EOF |
| 130 | |
| 131 | #------------------------------------------------------------------------------ |
| 132 | |
| 133 | tst_fail "substitutions: try to escape EOL in value" -q <<EOF |
| 134 | !-s |
| 135 | x=y\\ |
| 136 | EOF |
| 137 | |
| 138 | expect <<EOF |
| 139 | s:1: syntax error |
| 140 | EOF |
| 141 | |
| 142 | ############################################################################### |
| 143 |
Branches:
master
