FIX: Nested quotes in BBCode

Previously attributes such as `[test a='a"a' b="a'a"]` were not correctly
handled.

This amends the regex parser to ensure it correctly parses attributes
without breaking incorrectly on the first nested quote
This commit is contained in:
Sam Saffron 2020-09-21 08:55:56 +10:00
parent 50647366ed
commit a91ee45de9
No known key found for this signature in database
GPG Key ID: B9606168D2FFD9F5
2 changed files with 3 additions and 3 deletions

View File

@ -15,7 +15,7 @@ function trailingSpaceOnly(src, start, max) {
return true;
}
const ATTR_REGEX = /^\s*=(.+)$|((([a-z0-9]*)\s*)=)(["“”'].*?["“”']|\S+)/gi;
const ATTR_REGEX = /^\s*=(.+)$|((([a-z0-9]*)\s*)=)([“”].*?[“”]|['].*[']|["].*?["]|\S+)/gi;
// parse a tag [test a=1 b=2] to a data structure
// {tag: "test", attrs={a: "1", b: "2"}

View File

@ -1744,10 +1744,10 @@ HTML
end
it "adds attributes as data-attributes" do
cooked = PrettyText.cook("[wrap=toc name=\"pepper bell\" id=1]taco[/wrap]")
cooked = PrettyText.cook("[wrap=toc name=\"single quote's\" id='1\"2']taco[/wrap]")
html = <<~HTML
<div class="d-wrap" data-wrap="toc" data-name="pepper bell" data-id="1">
<div class="d-wrap" data-wrap="toc" data-name="single quote's" data-id="1&amp;quot;2">
<p>taco</p>
</div>
HTML