diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2012-07-11 01:27:15 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2012-07-11 01:27:15 +0200 |
commit | df8066a78ccd9b899244145f6be0171957a41a1e (patch) | |
tree | 1deceaacbf772c04dbcf84173b7b23e66b7f8598 | |
parent | e1db338a5187c008819932a4166f3aa27958c48e (diff) | |
download | busybox-w32-df8066a78ccd9b899244145f6be0171957a41a1e.tar.gz busybox-w32-df8066a78ccd9b899244145f6be0171957a41a1e.tar.bz2 busybox-w32-df8066a78ccd9b899244145f6be0171957a41a1e.zip |
awk: fix FS assignment behavior. Closes 5108
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 12 | ||||
-rwxr-xr-x | testsuite/awk.tests | 7 |
2 files changed, 19 insertions, 0 deletions
diff --git a/editors/awk.c b/editors/awk.c index d69720d64..42f6ef866 100644 --- a/editors/awk.c +++ b/editors/awk.c | |||
@@ -1812,6 +1812,18 @@ static void handle_special(var *v) | |||
1812 | is_f0_split = FALSE; | 1812 | is_f0_split = FALSE; |
1813 | 1813 | ||
1814 | } else if (v == intvar[FS]) { | 1814 | } else if (v == intvar[FS]) { |
1815 | /* | ||
1816 | * The POSIX-2008 standard says that changing FS should have no effect on the | ||
1817 | * current input line, but only on the next one. The language is: | ||
1818 | * | ||
1819 | * > Before the first reference to a field in the record is evaluated, the record | ||
1820 | * > shall be split into fields, according to the rules in Regular Expressions, | ||
1821 | * > using the value of FS that was current at the time the record was read. | ||
1822 | * | ||
1823 | * So, split up current line before assignment to FS: | ||
1824 | */ | ||
1825 | split_f0(); | ||
1826 | |||
1815 | mk_splitter(getvar_s(v), &fsplitter); | 1827 | mk_splitter(getvar_s(v), &fsplitter); |
1816 | 1828 | ||
1817 | } else if (v == intvar[RS]) { | 1829 | } else if (v == intvar[RS]) { |
diff --git a/testsuite/awk.tests b/testsuite/awk.tests index d4c390d31..f9c3b6b4d 100755 --- a/testsuite/awk.tests +++ b/testsuite/awk.tests | |||
@@ -217,4 +217,11 @@ end d | |||
217 | testing "awk handles empty ()" \ | 217 | testing "awk handles empty ()" \ |
218 | "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" "" | 218 | "awk 'BEGIN {print()}' 2>&1" "awk: cmd. line:1: Empty sequence\n" "" "" |
219 | 219 | ||
220 | testing "awk FS assignment" "awk '{FS=\":\"; print \$1}'" \ | ||
221 | "a:b\ne\n" \ | ||
222 | "" \ | ||
223 | "a:b c:d\ne:f g:h" | ||
224 | |||
225 | # testing "description" "command" "result" "infile" "stdin" | ||
226 | |||
220 | exit $FAILCOUNT | 227 | exit $FAILCOUNT |