diff options
author | Rémy Coutable <remy@rymai.me> | 2017-08-16 10:10:24 +0000 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-08-16 10:10:24 +0000 |
commit | 1b46a8360e0adffba79fad5730e94e333350f063 (patch) | |
tree | 73db4cf8ef38d8b99c345264901c44744e8a9806 /lib | |
parent | 765b1831687aac0a70819793890ac0e1ca5ae63f (diff) | |
parent | e99444bb2d3a249461825550fc6271f4e0ee8874 (diff) | |
download | gitlab-ce-1b46a8360e0adffba79fad5730e94e333350f063.tar.gz |
Merge branch '34643-fix-project-path-slugify' into 'master'
Fix CI_PROJECT_PATH_SLUG slugify
Closes #34643
See merge request !13350
Diffstat (limited to 'lib')
-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 |