diff options
author | francis <francis> | 2009-04-21 10:18:22 +0000 |
---|---|---|
committer | francis <francis> | 2009-04-21 10:18:22 +0000 |
commit | ed3b240e211a56e38fc4c57d1fe6d7053f8fb47f (patch) | |
tree | ff2ce2ef6f84c75a2394509feb0ee5191affd062 | |
parent | a6eb4edcfd9508c40ce80308a29791bd58b56897 (diff) |
Fix bug with not escaping name when used in regexp.
-rw-r--r-- | app/models/incoming_message.rb | 4 | ||||
-rw-r--r-- | spec/models/incoming_message_spec.rb | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 4f13e4c39..f0072899a 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -19,7 +19,7 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: francis@mysociety.org; WWW: http://www.mysociety.org/ # -# $Id: incoming_message.rb,v 1.199 2009-04-13 09:18:48 tony Exp $ +# $Id: incoming_message.rb,v 1.200 2009-04-21 10:18:22 francis Exp $ # TODO # Move some of the (e.g. quoting) functions here into rblib, as they feel @@ -480,7 +480,7 @@ class IncomingMessage < ActiveRecord::Base # Lotus notes quoting yeuch! def remove_lotus_quoting(text, replacement = "FOLDED_QUOTED_SECTION") text = text.dup - name = self.info_request.user.name + name = Regexp.escape(self.info_request.user.name) # To end of message sections # http://www.whatdotheyknow.com/request/university_investment_in_the_arm diff --git a/spec/models/incoming_message_spec.rb b/spec/models/incoming_message_spec.rb index d1738f6de..b84df3c0e 100644 --- a/spec/models/incoming_message_spec.rb +++ b/spec/models/incoming_message_spec.rb @@ -37,7 +37,26 @@ describe IncomingMessage, " display attachments" do foi_attachment.display_filename.should == expected_display_filename end +end + +describe IncomingMessage, " folding quoted parts of emails" do + + it "cope with [ in user names properly" do + @user = mock_model(User) + @user.stub!(:name).and_return("Sir [ Bobble") + @info_request = mock_model(InfoRequest) + @info_request.stub!(:user).and_return(@user) + + @incoming_message = IncomingMessage.new() + @incoming_message.info_request = @info_request + + # this gives a warning if [ is in the name + text = @incoming_message.remove_lotus_quoting("Sir [ Bobble \nSent by: \n") + text.should == "\n\nFOLDED_QUOTED_SECTION" + end end + + |