From 66423e62dceabbb9f688569e02e5a91e3bb0201c Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 5 May 2015 10:06:48 +1000 Subject: [PATCH] FIX: don't strip / mangle full quotes --- .../javascripts/discourse/controllers/composer.js.es6 | 2 +- app/assets/javascripts/discourse/lib/quote.js | 9 ++++++--- app/assets/javascripts/discourse/models/post.js.es6 | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/composer.js.es6 b/app/assets/javascripts/discourse/controllers/composer.js.es6 index 65df35cae..01698d22b 100644 --- a/app/assets/javascripts/discourse/controllers/composer.js.es6 +++ b/app/assets/javascripts/discourse/controllers/composer.js.es6 @@ -63,7 +63,7 @@ export default DiscourseController.extend({ const composer = this; return this.store.find('post', postId).then(function(post) { - const quote = Discourse.Quote.build(post, post.get("raw")); + const quote = Discourse.Quote.build(post, post.get("raw"), {raw: true, full: true}); composer.appendBlockAtCursor(quote); composer.set('model.loading', false); }); diff --git a/app/assets/javascripts/discourse/lib/quote.js b/app/assets/javascripts/discourse/lib/quote.js index c93cd5a89..f6bf7aab2 100644 --- a/app/assets/javascripts/discourse/lib/quote.js +++ b/app/assets/javascripts/discourse/lib/quote.js @@ -3,8 +3,11 @@ Discourse.Quote = { REGEXP: /\[quote=([^\]]*)\]((?:[\s\S](?!\[quote=[^\]]*\]))*?)\[\/quote\]/im, // Build the BBCode quote around the selected text - build: function(post, contents) { + build: function(post, contents, opts) { var contents_hashed, result, sansQuotes, stripped, stripped_hashed, tmp; + var full = opts && opts["full"]; + var raw = opts && opts["raw"]; + if (!contents) contents = ""; sansQuotes = contents.replace(this.REGEXP, '').trim(); @@ -30,8 +33,8 @@ Discourse.Quote = { contents_hashed = contents.replace(/[^a-zA-Z0-9]/g, ''); /* If the quote is the full message, attribute it as such */ - if (stripped_hashed === contents_hashed) result += ", full:true"; - result += "\"]\n" + sansQuotes + "\n[/quote]\n\n"; + if (full || stripped_hashed === contents_hashed) result += ", full:true"; + result += "\"]\n" + (raw ? contents : sansQuotes) + "\n[/quote]\n\n"; return result; } diff --git a/app/assets/javascripts/discourse/models/post.js.es6 b/app/assets/javascripts/discourse/models/post.js.es6 index e424d8111..ba3744ec0 100644 --- a/app/assets/javascripts/discourse/models/post.js.es6 +++ b/app/assets/javascripts/discourse/models/post.js.es6 @@ -398,7 +398,7 @@ Post.reopenClass({ loadQuote(postId) { return Discourse.ajax("/posts/" + postId + ".json").then(function (result) { const post = Discourse.Post.create(result); - return Discourse.Quote.build(post, post.get('raw')); + return Discourse.Quote.build(post, post.get('raw'), {raw: true, full: true}); }); },