mirror of
https://github.com/discourse/discourse.git
synced 2025-05-30 15:17:16 +08:00
FIX: remove unneeded escape when building a Quote
This commit is contained in:
@ -4,41 +4,32 @@ export default {
|
|||||||
|
|
||||||
// Build the BBCode quote around the selected text
|
// Build the BBCode quote around the selected text
|
||||||
build(post, contents, opts) {
|
build(post, contents, opts) {
|
||||||
var contents_hashed, result, sansQuotes, stripped, stripped_hashed, tmp;
|
|
||||||
var full = opts && opts["full"];
|
|
||||||
var raw = opts && opts["raw"];
|
|
||||||
|
|
||||||
if (!post) { return ""; }
|
if (!post) { return ""; }
|
||||||
|
|
||||||
if (!contents) contents = "";
|
if (!contents) contents = "";
|
||||||
|
|
||||||
sansQuotes = contents.replace(this.REGEXP, '').trim();
|
const sansQuotes = contents.replace(this.REGEXP, "").trim();
|
||||||
if (sansQuotes.length === 0) { return ""; }
|
if (sansQuotes.length === 0) { return ""; }
|
||||||
|
|
||||||
// Escape the content of the quote
|
// Strip the HTML from cooked
|
||||||
sansQuotes = sansQuotes.replace(/</g, "<")
|
const stripped = $("<div/>").html(post.get("cooked")).text();
|
||||||
.replace(/>/g, ">");
|
|
||||||
|
|
||||||
result = "[quote=\"" + post.get('username') + ", post:" + post.get('post_number') + ", topic:" + post.get('topic_id');
|
// Let's remove any non-word characters as a kind of hash.
|
||||||
|
// Yes it's not accurate but it should work almost every time we need it to.
|
||||||
|
// It would be unlikely that the user would quote another post that matches in exactly this way.
|
||||||
|
const sameContent = stripped.replace(/\W/g, "") === contents.replace(/\W/g, "");
|
||||||
|
|
||||||
/* Strip the HTML from cooked */
|
const params = [
|
||||||
tmp = document.createElement('div');
|
post.get("username"),
|
||||||
tmp.innerHTML = post.get('cooked');
|
`post:${post.get("post_number")}`,
|
||||||
stripped = tmp.textContent || tmp.innerText || "";
|
`topic:${post.get("topic_id")}`,
|
||||||
|
];
|
||||||
|
|
||||||
/*
|
opts = opts || {};
|
||||||
Let's remove any non alphanumeric characters as a kind of hash. Yes it's
|
|
||||||
not accurate but it should work almost every time we need it to. It would be unlikely
|
|
||||||
that the user would quote another post that matches in exactly this way.
|
|
||||||
*/
|
|
||||||
stripped_hashed = stripped.replace(/[^a-zA-Z0-9]/g, '');
|
|
||||||
contents_hashed = contents.replace(/[^a-zA-Z0-9]/g, '');
|
|
||||||
|
|
||||||
/* If the quote is the full message, attribute it as such */
|
if (opts["full"] || sameContent) params.push("full:true");
|
||||||
if (full || stripped_hashed === contents_hashed) result += ", full:true";
|
|
||||||
result += "\"]\n" + (raw ? contents : sansQuotes) + "\n[/quote]\n\n";
|
|
||||||
|
|
||||||
return result;
|
return `[quote="${params.join(", ")}"]\n${opts["raw"] ? contents : sansQuotes}\n[/quote]\n\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -717,10 +717,6 @@ QUnit.test("quotes", assert => {
|
|||||||
"[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n",
|
"[quote=\"eviltrout, post:1, topic:2, full:true\"]\n**lorem** ipsum\n[/quote]\n\n",
|
||||||
"keeps BBCode formatting");
|
"keeps BBCode formatting");
|
||||||
|
|
||||||
formatQuote("this is <not> a bug",
|
|
||||||
"[quote=\"eviltrout, post:1, topic:2\"]\nthis is <not> a bug\n[/quote]\n\n",
|
|
||||||
"it escapes the contents of the quote");
|
|
||||||
|
|
||||||
assert.cooked("[quote]\ntest\n[/quote]",
|
assert.cooked("[quote]\ntest\n[/quote]",
|
||||||
"<aside class=\"quote no-group\">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>",
|
"<aside class=\"quote no-group\">\n<blockquote>\n<p>test</p>\n</blockquote>\n</aside>",
|
||||||
"it supports quotes without params");
|
"it supports quotes without params");
|
||||||
|
Reference in New Issue
Block a user