Skip to content

Commit

Permalink
optparse: fix parser hang with split line option and description
Browse files Browse the repository at this point in the history
* specs/optparse_spec.yaml (optparse): Add a split line option
description to example help text.
* lib/optparse/init.lua (_init): Add a trailing space to each
option line to be matched as a separator with option patterns
using trailing %s.
(OptionParser): Add an example to luadocs.
* NEWS.md (Bug fixes): Update.

Reported-by: Jakub Jirutka <[email protected]>
Signed-off-by: Gary V. Vaughan <[email protected]>
  • Loading branch information
gvvaughan committed Jun 4, 2017
1 parent b3549c6 commit f787afb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
- don't crash when first unrecognized argument is also a handler
name (boolean, file, finished, flag, etc...)

- don't hang when help text option table formats long option name
on its own line before indented description.


## Noteworthy changes in release 1.1.1 (2016-02-07) [stable]

Expand Down
5 changes: 4 additions & 1 deletion lib/optparse/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ local function _init (self, spec)

-- Register option handlers according to the help text.
for _, spec in ipairs (specs) do
local options, handler = {}
-- append a trailing space separator to match %s in patterns below
local options, spec, handler = {}, spec .. ' '

-- Loop around each '-' prefixed option on this line.
while spec:sub (1, 1) == "-" do
Expand Down Expand Up @@ -776,6 +777,8 @@ return setmetatable ({
-- -b a short option with no long option
-- --long a long option with no short option
-- --another-long a long option with internal hypen
-- --really-long-option-name
-- with description on following line
-- -v, --verbose a combined short and long option
-- -n, --dryrun, --dry-run several spellings of the same option
-- -u, --name=USER require an argument
Expand Down
2 changes: 2 additions & 0 deletions specs/optparse_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ specify optparse:
--another-long a long option with internal hypen
--true a Lua keyword as an option name
--boolean an optparse handler as an option name
--really-long-option-name
with description on following line
-v, --verbose a combined short and long option
-n, --dryrun, --dry-run several spellings of the same option
-u, --name=USER require an argument
Expand Down

0 comments on commit f787afb

Please sign in to comment.