diff --git a/plugins/poll/assets/javascripts/poll_dialect.js b/plugins/poll/assets/javascripts/poll_dialect.js index 01c8ff37c..99bafe65f 100644 --- a/plugins/poll/assets/javascripts/poll_dialect.js +++ b/plugins/poll/assets/javascripts/poll_dialect.js @@ -8,7 +8,7 @@ const WHITELISTED_ATTRIBUTES = ["type", "name", "min", "max", "step", "order", "color", "background", "status"]; const WHITELISTED_STYLES = ["color", "background"]; - const ATTRIBUTES_REGEX = new RegExp("(" + WHITELISTED_ATTRIBUTES.join("|") + ")=[^\\s\\]]+", "g"); + const ATTRIBUTES_REGEX = new RegExp("(" + WHITELISTED_ATTRIBUTES.join("|") + ")=['\"]?[^\\s\\]]+['\"]?", "g"); Discourse.Dialect.replaceBlock({ start: /\[poll([^\]]*)\]([\s\S]*)/igm, @@ -44,8 +44,9 @@ // extract poll attributes (matches[1].match(ATTRIBUTES_REGEX) || []).forEach(function(m) { - var attr = m.split("="); - attributes[DATA_PREFIX + attr[0]] = attr[1]; + var attr = m.split("="), name = attr[0], value = attr[1]; + value = value.replace(/["']/g, ""); + attributes[DATA_PREFIX + name] = value; }); // we might need these values later... diff --git a/plugins/poll/spec/controllers/posts_controller_spec.rb b/plugins/poll/spec/controllers/posts_controller_spec.rb index 086258653..7c5263bfc 100644 --- a/plugins/poll/spec/controllers/posts_controller_spec.rb +++ b/plugins/poll/spec/controllers/posts_controller_spec.rb @@ -112,14 +112,14 @@ describe PostsController do describe "named polls" do it "should have different options" do - xhr :post, :create, { title: title, raw: "[poll name=foo]\n- A\n- A[/poll]" } + xhr :post, :create, { title: title, raw: "[poll name=""foo""]\n- A\n- A[/poll]" } expect(response).not_to be_success json = ::JSON.parse(response.body) expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_different_options", name: "foo")) end it "should have at least 2 options" do - xhr :post, :create, { title: title, raw: "[poll name=foo]\n- A[/poll]" } + xhr :post, :create, { title: title, raw: "[poll name='foo']\n- A[/poll]" } expect(response).not_to be_success json = ::JSON.parse(response.body) expect(json["errors"][0]).to eq(I18n.t("poll.named_poll_must_have_at_least_2_options", name: "foo"))