-
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
There seems to be an issue with `MySociety::Format.simplify_url_part` but we're not getting a full stack trace due to the source being outside of app/lib. This change should hopefully give us more information to allow us to debug this issue. See: #5870 #5871 #5873 #5874 #5876 #5877 #5878 #5879
- Loading branch information
Showing
10 changed files
with
46 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
require 'cgi' | ||
require 'unicode' | ||
require 'unidecoder' | ||
|
||
module Alaveteli | ||
module Format | ||
# Simplified a name to something usable in a URL | ||
def self.simplify_url_part(text, default_name, max_len = nil) | ||
text = text.downcase # this also clones the string, if we use downcase! we modify the original | ||
text = Unicode.normalize_KD(text) | ||
text = text.to_ascii.downcase | ||
|
||
text.gsub!(/(\s|-|_)/, "_") | ||
text.gsub!(/[^a-z0-9_]/, "") | ||
text.gsub!(/_+/, "_") | ||
text.gsub!(/^_*/, "") | ||
text.gsub!(/_*$/, "") | ||
|
||
# If required, trim down to size | ||
if not max_len.nil? | ||
if text.size > max_len | ||
text = text[0..(max_len-1)] | ||
end | ||
# removing trailing _ | ||
text.gsub!(/_*$/, "") | ||
end | ||
# Don't allow short (zero length!), or all numeric (clashes with identifiers) | ||
if text.size < 1 || text.match(/^[0-9]+$/) | ||
text = default_name # just do "user_1", "user_2" etc. | ||
end | ||
|
||
text | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters