Skip to content

Commit

Permalink
Allow escaping quotations in quoted macro arguments. (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
srbaker authored Jan 22, 2022
1 parent 6e00f83 commit 4434d23
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/gollum-lib/filter/macro.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Replace specified tokens with dynamically generated content.
class Gollum::Filter::Macro < Gollum::Filter
def extract(data)
quoted_arg = %r{".*?"}
quoted_arg = %r{".*?(?<!\\)"} # use a negative lookbehind to not terminate on a " preceeded by \
unquoted_arg = %r{[^,)]+}
named_arg = %r{[a-z0-9_]+=".*?"}

Expand All @@ -26,7 +26,7 @@ def extract(data)
if argument =~ /^([a-z0-9_]+)="(.*?)"/
opts[Regexp.last_match[1]] = Regexp.last_match[2]
elsif argument =~ /^"(.*)"$/
args << Regexp.last_match[1]
args << Regexp.last_match[1].gsub("\\\"", "\"")
else
args << argument
end
Expand Down
5 changes: 5 additions & 0 deletions test/test_macros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def render(opts)
assert_match(/@\(bar\)@/, @wiki.pages[0].formatted_data)
end

test "ListArgs with escaped quotation mark in quoted args" do
@wiki.write_page("ListArgsMacroPage", :markdown, '<<ListArgs("Goodbye \"cruel\" world")>>', commit_details)
assert_match(/@Goodbye "cruel" world@/, @wiki.pages[0].formatted_data)
end

test "ListArgs with a mix or arg styles" do
@wiki.write_page("ListArgsMacroPage", :markdown, '<<ListArgs("foo, bar, and baz", wombat, funny things)>>', commit_details)
assert_match(/@foo, bar, and baz@/, @wiki.pages[0].formatted_data)
Expand Down

0 comments on commit 4434d23

Please sign in to comment.