Class: Releases::Link
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Releases::Link
- Defined in:
- app/models/releases/link.rb
Constant Summary collapse
- FILEPATH_REGEX =
See gitlab.com/gitlab-org/gitlab/-/issues/218753 Regex modified to prevent catastrophic backtracking
%r{\A\/[^\/](?!.*\/\/.*)[\-\.\w\/]+[\da-zA-Z]+\z}
- FILEPATH_MAX_LENGTH =
128
Constants inherited from ApplicationRecord
Constants included from ResetOnUnionError
ResetOnUnionError::MAX_RESET_PERIOD
Instance Method Summary collapse
-
#filepath_format_valid? ⇒ Boolean
we use a custom validator here to prevent running the regex if the string is too long see gitlab.com/gitlab-org/gitlab/-/issues/273771.
- #hook_attrs ⇒ Object
- #internal? ⇒ Boolean
Methods inherited from ApplicationRecord
cached_column_list, #create_or_load_association, declarative_enum, default_select_columns, id_in, id_not_in, iid_in, pluck_primary_key, primary_key_in, #readable_by?, safe_ensure_unique, safe_find_or_create_by, safe_find_or_create_by!, #to_ability_name, underscore, where_exists, where_not_exists, with_fast_read_statement_timeout, without_order
Methods included from SensitiveSerializableHash
Instance Method Details
#filepath_format_valid? ⇒ Boolean
we use a custom validator here to prevent running the regex if the string is too long see gitlab.com/gitlab-org/gitlab/-/issues/273771
21 22 23 24 25 |
# File 'app/models/releases/link.rb', line 21 def filepath_format_valid? return if filepath.nil? # valid use case return errors.add(:filepath, "is too long (maximum is #{FILEPATH_MAX_LENGTH} characters)") if filepath.length > FILEPATH_MAX_LENGTH return errors.add(:filepath, 'is in an invalid format') unless FILEPATH_REGEX.match? filepath end |
#hook_attrs ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/models/releases/link.rb', line 40 def hook_attrs { id: id, link_type: link_type, name: name, url: url } end |
#internal? ⇒ Boolean
36 37 38 |
# File 'app/models/releases/link.rb', line 36 def internal? url.start_with?(release.project.web_url) end |