diff --git a/app/logical/post_edit.rb b/app/logical/post_edit.rb index a84b7265d..6c77f8a3b 100644 --- a/app/logical/post_edit.rb +++ b/app/logical/post_edit.rb @@ -33,7 +33,7 @@ class PostEdit @post = post @current_tag_names = current_tag_string.to_s.split @old_tag_names = old_tag_string.to_s.split - @new_tag_string = new_tag_string.to_s.gsub(/[[:space:]]/, " ").strip + @new_tag_string = new_tag_string.to_s.gsub(/[[:space:]]/, " ") @parser = StringParser.new(@new_tag_string) end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 2f5999333..6ba40cbcb 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -785,6 +785,31 @@ class PostTest < ActiveSupport::TestCase assert_equal([@post.id], @pool.post_ids) assert_equal("aaa bbb", @post.tag_string) end + + should "parse trailing backslash-escaped spaces correctly" do + @post.update!(tag_string: " a b c ") + assert_equal("a b c", @post.tag_string) + + @post.update!(tag_string: 'newpool:b\ a') + assert_equal("a", @post.tag_string) + assert_equal("b", Pool.last.name) + + @post.update!(tag_string: 'a newpool:c\ ') + assert_equal("a", @post.tag_string) + assert_equal("c", Pool.last.name) + + @post.update!(tag_string: 'a newpool:d\ ') + assert_equal("a", @post.tag_string) + assert_equal("d", Pool.last.name) + + @post.update!(tag_string: 'newpool:e\ a') + assert_equal("tagme", @post.tag_string) + assert_equal("e_a", Pool.last.name) + + @post.update!(tag_string: 'a newpool:f\\') + assert_equal("a", @post.tag_string) + assert_equal("f\\", Pool.last.name) + end end context "for a rating" do