Skip to content

Commit

Permalink
[api][webui] Simplify Package.valid_name? regular expression
Browse files Browse the repository at this point in the history
To DRY it up and make it more readable.
  • Loading branch information
ChrisBr committed Oct 18, 2017
1 parent c5652af commit 1332863
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1096,8 +1096,9 @@ def self.valid_name?(name, allow_multibuild = false)
return false if name == "0"
return true if %w(_product _pattern _project _patchinfo).include?(name)
# _patchinfo: is obsolete, just for backward compatibility
return name =~ /\A([a-zA-Z0-9]|(_product:|_patchinfo:)\w)[-+:\w\.]*\z/ ? true : false if allow_multibuild
name =~ /\A([a-zA-Z0-9]|(_product:|_patchinfo:)\w)[-+\w\.]*\z/ ? true : false
allowed_characters = /[-+\w\.#{ allow_multibuild ? ':' : '' }]/
reg_exp = /\A([a-zA-Z0-9]|(_product:|_patchinfo:)\w)#{allowed_characters}*\z/
reg_exp.match?(name)
end

def valid_name
Expand Down

0 comments on commit 1332863

Please sign in to comment.