onetrueawk/awk

Why do split(s,a,"c") and split(s,a,/c/) differ when s contains newline?

oguz-ismail opened this issue · 4 comments

See:

$ ./a.out 'BEGIN{split("axa\n",a,"x"); print "<"a[2]">"}'
<a>
$ ./a.out 'BEGIN{split("axa\n",a,/x/); print "<"a[2]">"}'
<a
>
$

This is reproducible on NetBSD, OpenBSD, and FreeBSDs awks too. But not on gawk, mawk, busybox awk and goawk.

What is the rationale for this behavior?

no rationale, there is a bug when split's third argument is a single char.

@plan9 Given the explicit check for a newline here I though it was deliberate

awk/run.c

Lines 1830 to 1831 in 2bab10b

while (*s != sep && *s != '\n' && *s != '\0')
s++;

Thanks

That looks like a copy/paste error to me; the check for newline should probably be removed. Arnold

think so. removed and tested yesterday, pushing shortly.
@oguz-ismail thanks for spotting the issue.