diff --git a/CHANGELOG b/CHANGELOG index 06b7413e616a2bad75105e9fb8e8af9bf882132f..187de477a81f7bf5c5721e724c811cf7d25e5cdd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -46,6 +46,8 @@ v 7.10.0 (unreleased) - Refactor issue filtering - AJAX selectbox for issue assignee and author filters - Fix issue with missing options in issue filtering dropdown if selected one + - Fix "Hello @username." references not working by no longer allowing usernames to end in period. + v 7.9.0 - Send EmailsOnPush email when branch or tag is created or deleted. diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 07d85d05bb48560b214e5acaf2f8e9bc138544eb..e2bcd25be216cbcd1c497eeadf121e9bbc5a9cd5 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -66,7 +66,7 @@ class Namespace < ActiveRecord::Base path.gsub!(/@.*\z/, "") path.gsub!(/\.git\z/, "") path.gsub!(/\A-/, "") - path.gsub!(/\z./, "") + path.gsub!(/.\z/, "") path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") counter = 0 diff --git a/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb new file mode 100644 index 0000000000000000000000000000000000000000..36e3faa53beea1e810b73c7d1303cebd1f24b430 --- /dev/null +++ b/db/migrate/20150324133047_remove_periods_at_ends_of_usernames.rb @@ -0,0 +1,39 @@ +class RemovePeriodsAtEndsOfUsernames < ActiveRecord::Migration + class Namespace < ActiveRecord::Base + class << self + def by_path(path) + where('lower(path) = :value', value: path.downcase).first + end + + def clean_path(path) + path.gsub!(/@.*\z/, "") + path.gsub!(/\.git\z/, "") + path.gsub!(/\A-/, "") + path.gsub!(/.\z/, "") + path.gsub!(/[^a-zA-Z0-9_\-\.]/, "") + + counter = 0 + base = path + while Namespace.by_path(path).present? + counter += 1 + path = "#{base}#{counter}" + end + + path + end + end + end + + def up + select_all("SELECT id, username FROM users WHERE username LIKE '%.'").each do |user| + username = quote_string(Namespace.clean_path(user["username"])) + execute "UPDATE users SET username = '#{username}' WHERE id = #{user["id"]}" + execute "UPDATE namespaces SET path = '#{username}', name = '#{username}' WHERE type = NULL AND owner_id = #{user["id"]}" + end + + select_all("SELECT id, path FROM namespaces WHERE type = 'Group' AND path LIKE '%.'").each do |group| + path = quote_string(Namespace.clean_path(group["path"])) + execute "UPDATE namespaces SET path = '#{path}' WHERE id = #{group["id"]}" + end + end +end diff --git a/lib/gitlab/markdown.rb b/lib/gitlab/markdown.rb index 41bb8d0892437e3985339e9ff20b02b89fee9b96..0b29138a729a17db2ef4e0942201cc441fe973a7 100644 --- a/lib/gitlab/markdown.rb +++ b/lib/gitlab/markdown.rb @@ -152,7 +152,7 @@ module Gitlab text end - NAME_STR = '[a-zA-Z0-9_][a-zA-Z0-9_\-\.]*' + NAME_STR = Gitlab::Regex::NAMESPACE_REGEX_STR PROJ_STR = "(?<project>#{NAME_STR}/#{NAME_STR})" REFERENCE_PATTERN = %r{ diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb index 08fcf9c6dc0d802286773a45ff3e70cf9cbd0fc9..0571574aa4fdc5e538835b398046e4723c5cfe34 100644 --- a/lib/gitlab/regex.rb +++ b/lib/gitlab/regex.rb @@ -2,13 +2,15 @@ module Gitlab module Regex extend self + NAMESPACE_REGEX_STR = '(?:[a-zA-Z0-9_\.][a-zA-Z0-9_\-\.]*[a-zA-Z0-9_\-]|[a-zA-Z0-9_])'.freeze + def namespace_regex - @namespace_regex ||= /\A[a-zA-Z0-9_.][a-zA-Z0-9_\-\.]*(?<!\.git)\z/.freeze + @namespace_regex ||= /\A#{NAMESPACE_REGEX_STR}\z/.freeze end def namespace_regex_message "can contain only letters, digits, '_', '-' and '.'. " \ - "Cannot start with '-' or end in '.git'" \ + "Cannot start with '-' or end in '.'." \ end