8000 Escape slash inside bracket expression by lucaswerkmeister · Pull Request #8 · dspinellis/pmonitor · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Escape slash inside bracket expression #8

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lucaswerkmeister
Copy link
Contributor

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 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 #7.

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.
@lucaswerkmeister
Copy link
Contributor Author

@fanis can you check if this solves the problem for you?

@fanis
Copy link
fanis commented Aug 15, 2018

After escaping that slash:

root@host:~/pmonitor# ./test-pmonitor.sh 
/bin/sh: 1: Syntax error: Unterminated quoted string
FAIL pmonitor: expected 50, got ''

Ensuring I got the change right:

root@host:~# grep 'fname.*dev.*test' pmonitor/pmonitor.sh 
        if (fname ~ /^\/dev\/[^\/]*$/ && system("test -b " fname) == 0) {
root@host:~# grep 'fname.*dev.*test' pmonitor/pmonitor
        if (fname ~ /^\/dev\/[^\/]*$/ && system("test -b " fname) == 0) {

@lucaswerkmeister
Copy link
Contributor Author

I’m getting the same “FAIL pmonitor: expected 50, got ''” both on this commit and on the parent (current master), so I suspect that’s unrelated. I’m confused by the first error though, not sure where that’s coming from.

@lucaswerkmeister
Copy link
Contributor Author

(#11 should fix the second error message.)

@udoyen
Copy link
udoyen commented Aug 20, 2018

This is yet to be merged!

@fanis
Copy link
fanis commented Aug 20, 2018

To clarify: it's not just the test suite that fails for me.

root@host:~/pmonitor# ./pmonitor --file=../test.bin
/bin/sh: 1: Syntax error: Unterminated quoted string

@lucaswerkmeister
Copy link
Contributor Author

@udoyen yes? this isn’t a high-activity repository, have some patience :)

@fanis can you check that you applied the patch correctly? I have the following sha256sum locally:

1ea0445284a9994402423367ce5a8c5ee1da3266bdeb95555c7f48cea698bf87  pmonitor.sh

@fanis
Copy link
fanis commented Aug 20, 2018

Yup:

# sha256sum pmonitor.sh 
1ea0445284a9994402423367ce5a8c5ee1da3266bdeb95555c7f48cea698bf87  pmonitor.sh
# sha256sum pmonitor
1ea0445284a9994402423367ce5a8c5ee1da3266bdeb95555c7f48cea698bf87  pmonitor

@lucaswerkmeister
Copy link
Contributor Author

Hm, then I’m not sure where this error could come from. Which shell is your /bin/sh?

@fanis
Copy link
fanis commented Aug 20, 2018
# ls -la /bin/sh
lrwxrwxrwx 1 root root 4 Jan 24  2017 /bin/sh -> dash

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

Successfully merging this pull request may close these issues.

3 participants
0