onetrueawk / awk

One true awk
Other
1.99k stars 160 forks source link

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

Closed oguz-ismail closed 6 months ago

oguz-ismail commented 6 months ago

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?

plan9 commented 6 months ago

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

oguz-ismail commented 6 months ago

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

https://github.com/onetrueawk/awk/blob/2bab10b60b3f4d3bbefdcb60410655f317d1a452/run.c#L1830-L1831

Thanks

arnoldrobbins commented 6 months ago

oguz-ismail @.***> wrote:

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

https://github.com/onetrueawk/awk/blob/2bab10b60b3f4d3bbefdcb60410655f317d1a452/run.c#L1830-L1831

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

Arnold

plan9 commented 6 months ago

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.