Skip to content

Commit

Permalink
Handle escaped doublequotes at the end of the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed May 28, 2024
1 parent 09172d3 commit a3e0d0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
7 changes: 5 additions & 2 deletions docopt_sh/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def __init__(self, script):
r'(?P<trimmed_before>\s*)'
r'(?P<trimmed_raw_value>(?:.(?!(?<![\\])\1))*?.?)'
r'(?P<trimmed_after>\s*))'
r'(?P<quote_end>\1)(?:\n|;)',
r'(?P<quote_end>(?<![\\])\1)(?:\n|;)',
script.contents,
re.MULTILINE | re.DOTALL
)
Expand All @@ -157,7 +157,10 @@ def __init__(self, script):
)
if process.returncode != 0:
raise DocoptScriptValidationError(
self, 'Unable to evaluate DOC= with system bash: %s' % process.stderr.decode('utf-8')
self, (
f"Unable to evaluate DOC= with system bash: {process.stderr.decode('utf-8')}"
+ f"The DOC region recognized was:\n{self.match.group(0)}" # type: ignore
)
)
self.trimmed_value = process.stdout.decode('utf-8')
self.trimmed_value_start = self.match.start('trimmed_raw_value') - self.match.end('quote_start') # type: ignore
Expand Down
12 changes: 12 additions & 0 deletions tests/docopt-sh-usecases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,15 @@ r"""Usage:
"""
$ prog test
{"a": false, "b": false, "ARG": "test", "OPT": null}

#
# Ending escaped double quote is parsable
#

r"""Usage:
prog

Ending with an escaped doublequote: \"
"""
$ prog
{}

0 comments on commit a3e0d0d

Please sign in to comment.