Skip to content

Commit

Permalink
[glob] Eliminate two assertions in _GlobUnescape.
Browse files Browse the repository at this point in the history
- Fixes #698
- Fixes fallout from #695 (failing test in spec/var-sub-quote)

There is still a different failing test case to remind us to overhaul
this code.  And we still need to fix issue #291 too.

This area of the code needs a bunch of work.
  • Loading branch information
Andy Chu committed Apr 7, 2020
1 parent 545c28a commit 7243d9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 12 additions & 5 deletions osh/glob_.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
glob_part_e, glob_part, glob_part_t,
glob_part__Literal, glob_part__Operator, glob_part__CharClass,
)
from core import util
from core.pyutil import stderr_line
#from core.util import log
from core import util
from core.util import log
from frontend import match

from typing import List, Tuple, cast, TYPE_CHECKING
if TYPE_CHECKING:
from core import optview
from frontend.match import SimpleLexer

_ = log


def LooksLikeGlob(s):
# type: (str) -> bool
Expand Down Expand Up @@ -125,14 +127,19 @@ def GlobUnescape(s): # used by cmd_eval
n = len(s)
while i < n:
c = s[i]
if c == '\\':
assert i != n - 1, 'Trailing backslash: %r' % s
if c == '\\' and i != n - 1:
# Suppressed this to fix bug #698, #628 is still there.
#assert i != n - 1, 'Trailing backslash: %r' % s
i += 1
c2 = s[i]
if c2 in GLOB_META_CHARS:
unescaped.append(c2)
else:
raise AssertionError("Unexpected escaped character %r" % c2)
#raise AssertionError("Unexpected escaped character %r" % c2)
# Hack to prevent crash for now. Need to rewrite this.
# Fell out of the fix to issue #695 to use _DQ_BACKSLASH in VS_ArgDQ.
#unescaped.append(c)
unescaped.append(c2)
else:
unescaped.append(c)
i += 1
Expand Down
4 changes: 3 additions & 1 deletion spec/var-sub-quote.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,9 @@ argv.py ${foo%d\'}
#### Strip a string with single quotes, double quoted
foo="'a b c d'"
argv.py "${foo%d\'}"
## stdout: ["'a b c "]
## STDOUT:
["'a b c "]
## END

#### The string to strip is space sensitive
foo='a b c d'
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ comments() {
}

word-split() {
sh-spec spec/word-split.test.sh --osh-failures-allowed 8 \
sh-spec spec/word-split.test.sh --osh-failures-allowed 7 \
${REF_SHELLS[@]} $OSH_LIST "$@"
}

Expand Down

0 comments on commit 7243d9d

Please sign in to comment.