FIX: Tolerate quotes with no username and no title

FIX: Tolerate quotes with no username and no title

diff --git a/app/assets/javascripts/discourse/components/quote-button.js.es6 b/app/assets/javascripts/discourse/components/quote-button.js.es6
index a703e5e..2d8df37 100644
--- a/app/assets/javascripts/discourse/components/quote-button.js.es6
+++ b/app/assets/javascripts/discourse/components/quote-button.js.es6
@@ -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"],
@@ -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;
       }

GitHub sha: 26da99a2

1 Like

This commit appears in #9132 which was approved by eviltrout. It was merged by riking.

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

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