From a91ee45de93c21637f9c062bd2eb6bf36a5213a1 Mon Sep 17 00:00:00 2001 From: Sam Saffron Date: Mon, 21 Sep 2020 08:55:56 +1000 Subject: [PATCH] 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 --- .../pretty-text/engines/discourse-markdown/bbcode-block.js | 2 +- spec/components/pretty_text_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js index 95eb2795907..4c0413358de 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js @@ -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"} diff --git a/spec/components/pretty_text_spec.rb b/spec/components/pretty_text_spec.rb index 12106c4ba2d..f5cca52d5c4 100644 --- a/spec/components/pretty_text_spec.rb +++ b/spec/components/pretty_text_spec.rb @@ -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 -
+

taco

HTML