ソースを参照

Always use 'raw' with read builtin

Turns out that read without params supports backslash escaping; that is,
`\t` gets translated to tab and `\` at the end of line connects with
next line.  Such feature is dangerous as implicit; read should almost
never be used without this parameter.

See [Bash Hackers wiki]1] for more.

  [1]: http://wiki.bash-hackers.org/commands/builtin/read#read_without_-r
Alois Mahdal 8 年 前
コミット
707991419b
共有1 個のファイルを変更した6 個の追加6 個の削除を含む
  1. 6
    6
      src/include/inigrep.sh

+ 6
- 6
src/include/inigrep.sh ファイルの表示

@@ -43,7 +43,7 @@ _inigrep__fltkey() {
43 43
     #
44 44
     # In listing mode, prints *key names* instead
45 45
     #
46
-    while IFS= read line;                           # '  key  =  val  '
46
+    while IFS= read -r line;                        # '  key  =  val  '
47 47
     do
48 48
         line="${line##*([[:space:]])}"              # line='key  =  val  '
49 49
         key="${line%%*([[:space:]])=*}"             # key='key'
@@ -65,7 +65,7 @@ _inigrep__fltsct() {
65 65
     local sct_ok=false
66 66
     local sct_name
67 67
     local line
68
-    while IFS= read line;
68
+    while IFS= read -r line;
69 69
     do
70 70
         if [[ $line =~ ^[[:space:]]*\[[^]]*\].* ]];     # IOW: 'spaces[name]anything'
71 71
         then
@@ -95,7 +95,7 @@ _inigrep__fltlst() {
95 95
     # Filter only section/keys/path names from the stream
96 96
     #
97 97
     local key="__NOKEY__" line="" sct="__NOSCT__"
98
-    while read line;
98
+    while read -r line;
99 99
     do
100 100
         case "$line" in
101 101
             \[*\]) sct=${line#[}; sct=${sct%]}; key=__NOKEY__     ;;
@@ -124,7 +124,7 @@ _inigrep__merge() {
124 124
     #
125 125
     local path
126 126
     debug -v strategy
127
-    while read path;
127
+    while read -r path;
128 128
     do
129 129
         test -f "$path" || continue
130 130
         case $strategy in
@@ -158,7 +158,7 @@ _inigrep__load() {
158 158
             debug -v FFOO_INIGREP_PATH
159 159
             echos "$FFOO_INIGREP_PATH" \
160 160
               | tr ':' '\n' \
161
-              | while read trydir;
161
+              | while read -r trydir;
162 162
                 do
163 163
                     test -n "$trydir" || continue
164 164
                     trypath="$trydir/$arg"
@@ -341,7 +341,7 @@ _inigrep__nl2colon() {
341 341
     #
342 342
     local idx=0     # current item index (zero-based)
343 343
     local path
344
-    while read path;
344
+    while read -r path;
345 345
     do
346 346
         test -z "$path" && continue
347 347
         test $idx -gt 0 && echo -n ':'