From 61db6c95d2dbd868aa600d5be44b03dc95d3f1d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 2 Sep 2014 01:18:06 +0200 Subject: [PATCH] FIX: couldn't start a 4-spaces block on the first line of a post --- lib/post_creator.rb | 2 +- lib/post_revisor.rb | 2 +- spec/components/post_creator_spec.rb | 6 +++++- spec/components/post_revisor_spec.rb | 7 +++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/post_creator.rb b/lib/post_creator.rb index 6ae33ebf9cb..456edcbf32b 100644 --- a/lib/post_creator.rb +++ b/lib/post_creator.rb @@ -203,7 +203,7 @@ class PostCreator end def setup_post - @opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw]).strip + @opts[:raw] = TextCleaner.normalize_whitespaces(@opts[:raw]).gsub(/\s+\z/, "") post = @topic.posts.new(raw: @opts[:raw], user: @user, diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index b065b5a4f9a..c9c8c6e9da6 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -19,7 +19,7 @@ class PostRevisor def revise!(editor, new_raw, opts = {}) @editor = editor @opts = opts - @new_raw = TextCleaner.normalize_whitespaces(new_raw).strip + @new_raw = TextCleaner.normalize_whitespaces(new_raw).gsub(/\s+\z/, "") # TODO this is not in a transaction - dangerous! return false unless should_revise? diff --git a/spec/components/post_creator_spec.rb b/spec/components/post_creator_spec.rb index d68df43235c..7b02d7747a9 100644 --- a/spec/components/post_creator_spec.rb +++ b/spec/components/post_creator_spec.rb @@ -468,7 +468,6 @@ describe PostCreator do end end - describe "suspended users" do it "does not allow suspended users to create topics" do user = Fabricate(:user, suspended_at: 1.month.ago, suspended_till: 1.month.from_now) @@ -479,5 +478,10 @@ describe PostCreator do end end + it "doesn't strip starting whitespaces" do + post = PostCreator.new(user, { title: "testing whitespace stripping", raw: " <-- whitespaces --> " }).create + post.raw.should == " <-- whitespaces -->" + end + end diff --git a/spec/components/post_revisor_spec.rb b/spec/components/post_revisor_spec.rb index 3be4d4fa22d..38a84f1b9b2 100644 --- a/spec/components/post_revisor_spec.rb +++ b/spec/components/post_revisor_spec.rb @@ -272,5 +272,12 @@ describe PostRevisor do }.to_not change { topic.excerpt } end end + + it "doesn't strip starting whitespaces" do + subject.revise!(post.user, " <-- whitespaces --> ") + post.reload + post.raw.should == " <-- whitespaces -->" + end + end end