FIX: allow bbcode to be unquoted for default

This commit is contained in:
Sam 2017-07-24 18:36:17 -04:00
parent 04eac9f14a
commit 4da98cdcfe
2 changed files with 28 additions and 5 deletions

View File

@ -11,7 +11,7 @@ function trailingSpaceOnly(src, start, max) {
return true; return true;
} }
const ATTR_REGEX = /((([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 // parse a tag [test a=1 b=2] to a data structure
// {tag: "test", attrs={a: "1", b: "2"} // {tag: "test", attrs={a: "1", b: "2"}
@ -76,12 +76,13 @@ export function parseBBCodeTag(src, start, max, multiline) {
let match, key, val; let match, key, val;
while(match = ATTR_REGEX.exec(raw)) { while(match = ATTR_REGEX.exec(raw)) {
key = match[3]; if (match[1]) {
if (key === '') {
key = '_default'; key = '_default';
} else {
key = match[4];
} }
val = match[4]; val = match[1] || match[5];
if (val) { if (val) {
val = val.trim(); val = val.trim();

View File

@ -47,7 +47,29 @@ describe PrettyText do
expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected)) expect(cook("[quote=\"EvilTrout, post:2, topic:#{topic.id}\"]\nddd\n[/quote]", topic_id: 1)).to eq(n(expected))
end end
it "indifferent about curlies" do it "indifferent about missing quotations" do
md = <<~MD
[quote=#{user.username}, post:123, topic:456, full:true]
ddd
[/quote]
MD
html = <<~HTML
<aside class="quote" data-post="123" data-topic="456" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt width="20" height="20" src="//test.localhost/uploads/default/avatars/42d/57c/46ce7ee487/40.png" class="avatar"> #{user.username}:</div>
<blockquote>
<p>ddd</p>
</blockquote>
</aside>
HTML
expect(PrettyText.cook(md)).to eq(html.strip)
end
it "indifferent about curlies and no curlies" do
md = <<~MD md = <<~MD
[quote=#{user.username}, post:123, topic:456, full:true”] [quote=#{user.username}, post:123, topic:456, full:true”]