diff options
author | vanadium23 <chernoffivan@gmail.com> | 2017-08-07 21:00:11 +0300 |
---|---|---|
committer | vanadium23 <chernoffivan@gmail.com> | 2017-08-15 08:22:56 +0300 |
commit | e99444bb2d3a249461825550fc6271f4e0ee8874 (patch) | |
tree | 00d7db971c464d3ad76d84b92941d37c328ef724 /lib/gitlab/utils.rb | |
parent | ae81bfd3155f4036c3a9c877177e02a70eb2553a (diff) |
Fix CI_PROJECT_PATH_SLUG slugify
Diffstat (limited to 'lib/gitlab/utils.rb')
-rw-r--r-- | lib/gitlab/utils.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/gitlab/utils.rb b/lib/gitlab/utils.rb index fa182c4deda..9670c93759e 100644 --- a/lib/gitlab/utils.rb +++ b/lib/gitlab/utils.rb @@ -14,6 +14,19 @@ module Gitlab str.force_encoding(Encoding::UTF_8) end + # A slugified version of the string, suitable for inclusion in URLs and + # domain names. Rules: + # + # * Lowercased + # * Anything not matching [a-z0-9-] is replaced with a - + # * Maximum length is 63 bytes + # * First/Last Character is not a hyphen + def slugify(str) + return str.downcase + .gsub(/[^a-z0-9]/, '-')[0..62] + .gsub(/(\A-+|-+\z)/, '') + end + def to_boolean(value) return value if [true, false].include?(value) return true if value =~ /^(true|t|yes|y|1|on)$/i |