Skip to content

Commit a3e0d0d

Browse files
committed
Handle escaped doublequotes at the end of the doc
1 parent 09172d3 commit a3e0d0d

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

docopt_sh/script.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def __init__(self, script):
139139
r'(?P<trimmed_before>\s*)'
140140
r'(?P<trimmed_raw_value>(?:.(?!(?<![\\])\1))*?.?)'
141141
r'(?P<trimmed_after>\s*))'
142-
r'(?P<quote_end>\1)(?:\n|;)',
142+
r'(?P<quote_end>(?<![\\])\1)(?:\n|;)',
143143
script.contents,
144144
re.MULTILINE | re.DOTALL
145145
)
@@ -157,7 +157,10 @@ def __init__(self, script):
157157
)
158158
if process.returncode != 0:
159159
raise DocoptScriptValidationError(
160-
self, 'Unable to evaluate DOC= with system bash: %s' % process.stderr.decode('utf-8')
160+
self, (
161+
f"Unable to evaluate DOC= with system bash: {process.stderr.decode('utf-8')}"
162+
+ f"The DOC region recognized was:\n{self.match.group(0)}" # type: ignore
163+
)
161164
)
162165
self.trimmed_value = process.stdout.decode('utf-8')
163166
self.trimmed_value_start = self.match.start('trimmed_raw_value') - self.match.end('quote_start') # type: ignore

tests/docopt-sh-usecases.txt

+12
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,15 @@ r"""Usage:
125125
"""
126126
$ prog test
127127
{"a": false, "b": false, "ARG": "test", "OPT": null}
128+
129+
#
130+
# Ending escaped double quote is parsable
131+
#
132+
133+
r"""Usage:
134+
prog
135+
136+
Ending with an escaped doublequote: \"
137+
"""
138+
$ prog
139+
{}

0 commit comments

Comments
 (0)