From dd76ba90b394f582ed652a7ef571d471d3b0dc4a Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 23 May 2018 11:55:02 +0200 Subject: [PATCH] FIX: bbcode regex was greedy and preventing quotes --- .../engines/discourse-markdown/bbcode-block.js.es6 | 2 +- test/javascripts/lib/bbcode-test.js.es6 | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/javascripts/lib/bbcode-test.js.es6 diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js.es6 index b35d716189e..b7348d0262f 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/bbcode-block.js.es6 @@ -11,7 +11,7 @@ function trailingSpaceOnly(src, start, max) { return true; } -const ATTR_REGEX = /^\s*=(.+)$|((([a-z0-9]*)\s*)=)(["“”'].*["“”']|\S+)/ig; +const ATTR_REGEX = /^\s*=(.+)$|((([a-z0-9]*)\s*)=)(["“”'].*?["“”']|\S+)/ig; // parse a tag [test a=1 b=2] to a data structure // {tag: "test", attrs={a: "1", b: "2"} diff --git a/test/javascripts/lib/bbcode-test.js.es6 b/test/javascripts/lib/bbcode-test.js.es6 new file mode 100644 index 00000000000..3f306877740 --- /dev/null +++ b/test/javascripts/lib/bbcode-test.js.es6 @@ -0,0 +1,11 @@ +import { parseBBCodeTag } from 'pretty-text/engines/discourse-markdown/bbcode-block'; + +QUnit.module("lib:pretty-text:bbcode"); + +QUnit.test("block with multiple quoted attributes", assert => { + const parsed = parseBBCodeTag('[test one="foo" two="bar bar"]', 0, 30); + + assert.equal(parsed.tag, "test"); + assert.equal(parsed.attrs.one, "foo"); + assert.equal(parsed.attrs.two, "bar bar"); +});