8000 Fix broken test: option groups without a newline between them were no… · patrickjwhite/docopt.cpp@5d0641b · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d0641b

Browse files
committed
Fix broken test: option groups without a newline between them were not being detected
1 parent 981200c commit 5d0641b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

docopt.cpp

Lines changed: 9 additions & 1 deletion
< 7EAA /tr>
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,16 @@ std::vector<T*> flat_filter(Pattern& pattern) {
547547
}
548548

549549
std::vector<std::string> parse_section(std::string const& name, std::string const& source) {
550+
// ECMAScript regex only has "?=" for a non-matching lookahead. In order to make sure we always have
551+
// a newline to anchor our matching, we have to avoid matching the final newline of each grouping.
552+
// Therefore, our regex is adjusted from the docopt Python one to use ?= to match the newlines before
553+
// the following lines, rather than after.
550554
std::regex const re_section_pattern {
551-
"(?:^|\\n)([^\\n]*" + name + "[^\\n]*\\n?(?:[ \\t].*?(?:\\n|$))*)",
555+
"(?:^|\\n)" // anchored at a linebreak (or start of string)
556+
"("
557+
"[^\\n]*" + name + "[^\\n]*(?=\\n?)" // a line that contains the name
558+
"(?:\\n[ \\t].*?(?=\\n|$))*" // followed by any number of lines that are indented
559+
")",
552560
std::regex::icase
553561
};
554562

0 commit comments

Comments
 (0)
0