Skip to content

Commit

Permalink
FIX: Tolerate quotes with no username and no title
Browse files Browse the repository at this point in the history
  • Loading branch information
riking committed Mar 6, 2020
1 parent f7ea2fd commit 26da99a
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions app/assets/javascripts/discourse/components/quote-button.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import Component from "@ember/component";
import discourseDebounce from "discourse/lib/debounce";
import { selectedText, selectedElement } from "discourse/lib/utilities";

function getQuoteTitle(element) {
const titleEl = element.querySelector(".title");
if (!titleEl) return;
return titleEl.textContent.trim().replace(/:$/, "");
}

export default Component.extend({
classNames: ["quote-button"],
classNameBindings: ["visible"],
Expand Down Expand Up @@ -55,12 +61,7 @@ export default Component.extend({
element = element.parentElement
) {
if (element.tagName === "ASIDE" && element.classList.contains("quote")) {
opts.username =
element.dataset.username ||
element
.querySelector(".title")
.textContent.trim()
.replace(/:$/, "");
opts.username = element.dataset.username || getQuoteTitle(element);
opts.post = element.dataset.post;
opts.topic = element.dataset.topic;
}
Expand Down

2 comments on commit 26da99a

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Régis Hanol posted:

This should probably be tested to ensure we don’t regress.

@discoursereviewbot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

posted:

I can't figure out how to feed specific post content to the QUnit tests. Maybe that was never implemented.

Please sign in to comment.