gsub does not handle \ consistently

Bug #102208 reported by Schplurtz le déboulonné
2
Affects Status Importance Assigned to Milestone
mawk (Ubuntu)
Incomplete
Undecided
Unassigned

Bug Description

Binary package hint: mawk

Hello,

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 6.06.1 LTS
Release: 6.06
Codename: dapper

$ dpkg -l mawk
ii mawk 1.3.3-11ubuntu1 a pattern scanning

The interpretation of "\\" in replacement is semi random and does not conform to the man page description.

                    echo '\' | mawk '{ gsub( /\\/, "\\ \\" ) }'
produces the expected and documented answer
                    \ \
but
                    echo '\' | mawk '{ gsub( /\\/, "\\\\" ) }'
only produce one single backslash instead of two. Others awks (gawk, Solaris nawk, MacOSX 10.4.8 awk) do print 2 backslashes.

/Christophe

Revision history for this message
Daniel T Chen (crimsun) wrote :

Is this symptom still reproducible in 8.10 beta? (Note that the syntax seems ill on bash, mksh, ...)

Changed in mawk:
status: New → Incomplete
Revision history for this message
Peter Cordes (peter-cordes) wrote :

Ubuntu AMD64 8.10.

peter@tesla:~$ echo '\' | mawk '{ gsub( /\\/, "\\\\" ); print }'
\
peter@tesla:~$ echo '\' | mawk '{ gsub( /\\/, "\\ \\" ); print }'
\ \

The syntax is fine, it's all single-quoted. The submitter left out a print, though. You can check that mawk is getting the right args and input with
strace -eexecve,read,write mawk
That produces a veritable forest of backslashes, so you can definitely see that they're not being eaten by bash.

There seem to be a few bugs in mawk's gsub: e.g.
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=100808

 This bug is a different kind of wrong matching of regexes, so I didn't mark this bug as being the same bug, though.

Revision history for this message
rusivi2 (rusivi2-deactivatedaccount) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. I noticed the package your bugging is updated in Lucid. Does this occur in it? If so, please feel free to mark this bug as new. Thanks in advance!

Revision history for this message
Thomas Dickey (dickey-his) wrote : Re: [Bug 102208] Re: gsub does not handle \ consistently

On Wed, 15 Sep 2010, rusivi1 wrote:

> Thank you for taking the time to report this bug and helping to make
> Ubuntu better. I noticed the package your bugging is updated in Lucid.
> Does this occur in it? If so, please feel free to mark this bug as new.
> Thanks in advance!

It is a bug unrelated to changes in upstream (has to do with the way
tokens are stored). It's not addressed in any of the package changes.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net

Revision history for this message
Schplurtz le déboulonné (schplurtz) wrote :

Hello,

The bug is still there in Lucid.

After reading Thomas Dickey's comment, I think there is no need to mark the bug as new. Am I right ?

/Christophe

Revision history for this message
Thomas Dickey (dickey-his) wrote :

On Fri, 17 Sep 2010, Schplurtz le déboulonné wrote:

> Hello,
>
> The bug is still there in Lucid.
>
> After reading Thomas Dickey's comment, I think there is no need to mark
> the bug as new. Am I right ?

right - it's a longstanding bug. iirc, mawk is reading the token in a
context where it's not quite sure that it's a pattern.

--
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.