Bug 12486

Summary: awk: length without () does not work properly
Product: Busybox Reporter: wolf+busybox
Component: Standard ComplianceAssignee: unassigned
Status: RESOLVED FIXED    
Severity: normal CC: busybox-cvs, wolf+busybox
Priority: P5    
Version: 1.31.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:
Attachments: Additions to the test suite
Implementation of a "fix"

Description wolf+busybox 2020-01-18 00:52:28 UTC
Created attachment 8346 [details]
Additions to the test suite

While 8371 did solve part of length without parentheses behaviour, there are still other cases that do not work, for example:

```
+$ echo | busybox awk '{ print length, 1 }'
awk: cmd. line:1: Unexpected token
+$ echo | awk '{ print length, 1 }'
0 1
+$ echo | busybox awk '{ print length 1 }'
awk: cmd. line:1: Unexpected token
+$ echo | awk '{ print length 1 }'
01
```

the length is also legal in the pattern part:

```
+$ echo | busybox awk 'length == 0 { print "foo" }'
awk: cmd. line:1: Unexpected token
+$ echo | awk 'length == 0 { print "foo" }'
foo
```

and in ifs

```
+$ echo | busybox awk '{ if (length == 0) { print "bar" } }'
awk: cmd. line:1: Unexpected token
:$ echo | awk '{ if (length == 0) { print "bar" } }'
bar
```

Comparisons are done on up-to-date Archlinux on amd64 using:

```
+   $ busybox --help | head -1
BusyBox v1.31.1 () multi-call binary.
+   $ awk --version | head -n 1
GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.1.2)
```


I did try to make a patch for this, but after few hours I've concluded that I have no idea how. What I have is addition to the test suite for awk, which is attached to this bug report.

EDIT: Well... I figured out something. It's ugly, but it works. It would probably be better to solve it in more elegant way, but still attaching it for completeness' sake.
Comment 1 wolf+busybox 2020-01-18 00:53:00 UTC
Created attachment 8351 [details]
Implementation of a "fix"
Comment 2 Denys Vlasenko 2020-02-02 22:34:00 UTC
Fixed in git, thanks! More examples?
Comment 3 wolf+busybox 2020-02-04 19:36:45 UTC
Nope, cannot think of anything else. Thx for fixing this.