Class: API::Validations::Validators::GitRef

Inherits:
Grape::Validations::Validators::Base
  • Object
show all
Defined in:
lib/api/validations/validators/git_ref.rb

Constant Summary collapse

INVALID_CHARS =

There are few checks that a Git reference should pass through to be valid reference. The link contains some rules that have been added to this validator. mirrors.edge.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html We have skipped some checks that are optional and can be skipped for exception. We also check for control characters, More info on ctrl chars - ruby-doc.org/core-2.7.0/Regexp.html#class-Regexp-label-Character+Classes

Regexp.union('..', '\\', '@', '@{', ' ', '~', '^', ':', '*', '?', '[', /[[:cntrl:]]/).freeze
GIT_REF_LENGTH =
(1..1024)

Instance Method Summary collapse

Instance Method Details

#validate_param!(attr_name, params) ⇒ Object

Raises:

  • (Grape::Exceptions::Validation)


15
16
17
18
19
20
21
22
23
24
# File 'lib/api/validations/validators/git_ref.rb', line 15

def validate_param!(attr_name, params)
  revision = params[attr_name]

  return unless invalid_character?(revision)

  raise Grape::Exceptions::Validation.new(
    params: [@scope.full_name(attr_name)],
    message: 'should be a valid reference path'
  )
end