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

Bug in _egrep_o() when extended regex passed in and sed emulation used #2385

Open
dkerr64 opened this issue Jul 11, 2019 · 1 comment
Open

Comments

@dkerr64
Copy link
Contributor

dkerr64 commented Jul 11, 2019

_egrep_o() function accepts extended regex and on systems that do not have egrep uses sed to emulate egrep. This is failing on the specific regex I was using in dns_freedns.sh. See #2305 for the problem I was working on.

The problem is that egrep requires extended regex, and if you pass in non-extended it may fail if there are special characters. But on systems that do not have egrep, the _egrep_o function uses sed to emulate egrep. This fails with the extended regex, but works with the regular regex.

Below script illustrates the problem... I split your _egrep_o function into two to illustrate the problem on systems that have egrep (ie, removed the test for failure with egrep)

#!/usr/bin/env sh

_egrep_o1() {
  egrep -o "$1" 2>/dev/null
}

_egrep_o2() {
  sed -n 's/.*\('"$1"'\).*/\1/p'
}

txt="<tr><td>example.com</td><tdalign=right><ahref=/subdomain/edit.php?edit_domain_id=1234567>[add]</a></td></tr></table></td></tr>"

echo "Test 1 (grep -o)"
echo "$txt" | grep -o "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 2 (egrep -o with non-extended regex, should fail)"
echo "$txt" | _egrep_o1 "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 3 (sed emulation of egrep -o with non-extended regex, should fail like test 2"
echo "$txt" | _egrep_o2 "edit\.php?edit_domain_id=[0-9a-zA-Z]*"
echo "Test 4 (egrep -o with extended regex, should work"
echo "$txt" | _egrep_o1 "edit\.php\?edit_domain_id=[0-9a-zA-Z]+"
echo "Test 5 (sed emulation of egrep -o with extended regex, should work like test 4"
echo "$txt" | _egrep_o2 "edit\.php\?edit_domain_id=[0-9a-zA-Z]+"
echo "End"
exit
@codestation
Copy link

codestation commented Jul 29, 2019

This bug also breaks dns_linode.sh and dns_linode_v4.sh when used on the docker image. Seems like _egrep_o is broken on alpine.

edit: sorry, my bug seems more like #1364

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