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 HasCheckConstraints
HasCheckConstraints::NOT_NULL_CHECK_PATTERN
Constants included from ResetOnColumnErrors
ResetOnColumnErrors::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, current_transaction, declarative_enum, default_select_columns, delete_all_returning, #deleted_from_database?, id_in, id_not_in, iid_in, nullable_column?, 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 Organizations::Sharding
Methods included from ResetOnColumnErrors
#reset_on_union_error, #reset_on_unknown_attribute_error
Methods included from Gitlab::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 26 |
# 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 errors.add(:filepath, 'is in an invalid format') unless FILEPATH_REGEX.match? filepath end |
#hook_attrs ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'app/models/releases/link.rb', line 41 def hook_attrs { id: id, link_type: link_type, name: name, url: url } end |
#internal? ⇒ Boolean
37 38 39 |
# File 'app/models/releases/link.rb', line 37 def internal? url.start_with?(release.project.web_url) end |