aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/awk.c13
-rwxr-xr-xtestsuite/awk.tests7
2 files changed, 15 insertions, 5 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 2af823808..b3748b502 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2049,13 +2049,17 @@ static int awk_split(const char *s, node *spl, char **slist)
2049 } 2049 }
2050 return n; 2050 return n;
2051 } 2051 }
2052 /* space split */ 2052 /* space split: "In the special case that FS is a single space,
2053 * fields are separated by runs of spaces and/or tabs and/or newlines"
2054 */
2053 while (*s) { 2055 while (*s) {
2054 s = skip_whitespace(s); 2056 /* s = skip_whitespace(s); -- WRONG (also skips \v \f \r) */
2057 while (*s == ' ' || *s == '\t' || *s == '\n')
2058 s++;
2055 if (!*s) 2059 if (!*s)
2056 break; 2060 break;
2057 n++; 2061 n++;
2058 while (*s && !isspace(*s)) 2062 while (*s && !(*s == ' ' || *s == '\t' || *s == '\n'))
2059 *s1++ = *s++; 2063 *s1++ = *s++;
2060 *s1++ = '\0'; 2064 *s1++ = '\0';
2061 } 2065 }
@@ -2304,7 +2308,6 @@ static int awk_getline(rstream *rsm, var *v)
2304 setvar_i(intvar[ERRNO], errno); 2308 setvar_i(intvar[ERRNO], errno);
2305 } 2309 }
2306 b[p] = '\0'; 2310 b[p] = '\0';
2307
2308 } while (p > pp); 2311 } while (p > pp);
2309 2312
2310 if (p == 0) { 2313 if (p == 0) {
@@ -3145,7 +3148,7 @@ static var *evaluate(node *op, var *res)
3145 /* make sure that we never return a temp var */ 3148 /* make sure that we never return a temp var */
3146 if (L.v == TMPVAR0) 3149 if (L.v == TMPVAR0)
3147 L.v = res; 3150 L.v = res;
3148 /* if source is a temporary string, jusk relink it to dest */ 3151 /* if source is a temporary string, just relink it to dest */
3149 if (R.v == TMPVAR1 3152 if (R.v == TMPVAR1
3150 && !(R.v->type & VF_NUMBER) 3153 && !(R.v->type & VF_NUMBER)
3151 /* Why check !NUMBER? if R.v is a number but has cached R.v->string, 3154 /* Why check !NUMBER? if R.v is a number but has cached R.v->string,
diff --git a/testsuite/awk.tests b/testsuite/awk.tests
index ddc51047b..8ab1c6891 100755
--- a/testsuite/awk.tests
+++ b/testsuite/awk.tests
@@ -540,4 +540,11 @@ testing 'awk assign while assign' \
540│ trim/eff : 57.02%/26, 0.00% │ [cpu000:100%] 540│ trim/eff : 57.02%/26, 0.00% │ [cpu000:100%]
541└────────────────────────────────────────────────────┘^C" 541└────────────────────────────────────────────────────┘^C"
542 542
543# If field separator FS=' ' (default), fields are split only on
544# space or tab or linefeed, NOT other whitespace.
545testing 'awk does not split on CR (char 13)' \
546 "awk '{ \$1=\$0; print }'" \
547 'word1 word2 word3\r word2 word3\r\n' \
548 '' 'word1 word2 word3\r'
549
543exit $FAILCOUNT 550exit $FAILCOUNT