aboutsummaryrefslogtreecommitdiffstats
path: root/app/models
diff options
context:
space:
mode:
authorfrancis <francis>2009-09-09 17:01:46 +0000
committerfrancis <francis>2009-09-09 17:01:46 +0000
commit1f5e5c667a84dbed09ae3ae9ef809de78402e55e (patch)
treef67565f363fe014a5bc04c3d295492475c520da9 /app/models
parentf4bef02305506500a209e587937d8297001a3e8f (diff)
Change algorithm for showing filenames so works with odd cases better
Diffstat (limited to 'app/models')
-rw-r--r--app/models/incoming_message.rb25
1 files changed, 23 insertions, 2 deletions
diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb
index d76676664..84dd9840b 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.218 2009-09-09 15:19:06 francis Exp $
+# $Id: incoming_message.rb,v 1.219 2009-09-09 17:01:47 francis Exp $
# TODO
# Move some of the (e.g. quoting) functions here into rblib, as they feel
@@ -236,13 +236,34 @@ class FOIAttachment
return ""
end
- def display_filename
+ # Called by controller so old filenames still work
+ def old_display_filename
filename = self._internal_display_filename
+ # Convert weird spaces (e.g. \n) to normal ones
+ filename = filename.gsub(/\s/, " ")
# Remove slashes, they mess with URLs
filename = filename.gsub(/\//, "-")
return filename
+ end
+
+ # XXX changing this will break existing URLs, so have a care - maybe
+ # make another old_display_filename see above
+ def display_filename
+ filename = self._internal_display_filename
+
+ # Remove weird spaces
+ filename = filename.gsub(/\s+/, " ")
+ # Remove non-alphabetic characters
+ filename = filename.gsub(/[^A-Za-z0-9.]/, " ")
+ # Remove spaces near dots
+ filename = filename.gsub(/\s*\.\s*/, ".")
+ # Compress adjacent spaces down to a single one
+ filename = filename.gsub(/\s+/, " ")
+ filename = filename.strip
+
+ return filename
end
def _internal_display_filename