Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regular expression compile failed (bad class) #7

Open
fanis opened this issue Aug 8, 2018 · 1 comment
Open

Regular expression compile failed (bad class) #7

fanis opened this issue Aug 8, 2018 · 1 comment

Comments

@fanis
Copy link

fanis commented Aug 8, 2018

Cloned and make install latest version but can't seem to get it to work on a just installed Debian 9.4 machine.

# ls -la test.bin
-rw-r--r-- 1 root root 1073741824 Aug  8 13:09 test.bin

(on another terminal, performing a copy on test.bin)

# pmonitor --file=test.bin
awk: line 12: regular expression compile failed (bad class -- [], [^] or [)
^/dev/[^
awk: line 12: syntax error at or near ]
awk: line 12: runaway regular expression / && system ...

Attempting to run tests:

~/pmonitor# ./test-pmonitor.sh 
awk: line 12: regular expression compile failed (bad class -- [], [^] or [)
^/dev/[^
awk: line 12: syntax error at or near ]
awk: line 12: runaway regular expression / && system ...
FAIL pmonitor: expected 50, got ''
@lucaswerkmeister
Copy link
Contributor

Hm, apparently a common AWK on Debian Stretch is mawk. (It all goes through the alternatives system, so I hesitate to call it “the default”, but /etc/alternatives/awk points to /usr/bin/mawk on my Debian Stretch server as well.) And the mawk version shipped by Debian (1.3.3) doesn’t seem to support the regex we use to detect devices, /^\/dev\/[^/]*$/. However, the mawk version I have on my Arch Linux home system (1.3.4) does support it. I’m not sure if this is really a change between 1.3.3 and 1.3.4, or if Debian and Arch perhaps build the package differently?

Regardless – escaping the / inside the character class seems to fix the issue in all the AWK versions I have available to test (Debian’s mawk 1.3.3 and Arch’s gawk 4.2.1, mawk 1.3.4 and nawk 20121220), so I’ll submit a pull request with that fix. Thanks for reporting!

lucaswerkmeister added a commit to lucaswerkmeister/pmonitor that referenced this issue Aug 14, 2018
Many AWK implementations appears to allow unescaped slashes inside a
bracket expression in a regular expression literal, consistent with the
way that most metacharacters lose their meaning inside bracket
expressions (tested: GNU Awk 4.2.1, mawk 1.3.4, and BWK awk (nawk)
20121220, all on Arch Linux); however, some versions also appear to
require such a slash to be escaped (tested: mawk 1.3.3 on Debian
Stretch), and this appears to be consistent with POSIX, which in the
Lexical Conventions, number 6, states that “[a]n ERE constant shall be
terminated by the first unescaped occurrence of the <slash> character
after the one that begins the ERE constant.” Escaping the slash appears
to be safe in all tested versions (that is, it does not count the
backslash as part of the bracket expression), so let’s do that to ensure
the program also works with mawk 1.3.3 on Debian Stretch, fixing dspinellis#7.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants