Commit 31b02fc2 authored by Douwe Maan's avatar Douwe Maan

Don't allow spaces in dependency linker value regex

parent e20eb712
module Gitlab module Gitlab
module DependencyLinker module DependencyLinker
class BaseLinker class BaseLinker
URL_REGEX = %r{https?://[^'"]+}.freeze URL_REGEX = %r{https?://[^'" ]+}.freeze
REPO_REGEX = %r{[^/'"]+/[^/'"]+}.freeze REPO_REGEX = %r{[^/'" ]+/[^/'" ]+}.freeze
class_attribute :file_type class_attribute :file_type
...@@ -69,7 +69,7 @@ module Gitlab ...@@ -69,7 +69,7 @@ module Gitlab
@highlighted_lines ||= highlighted_text.lines @highlighted_lines ||= highlighted_text.lines
end end
def regexp_for_value(value, default: /[^'"]+/) def regexp_for_value(value, default: /[^'" ]+/)
case value case value
when Array when Array
Regexp.union(value.map { |v| regexp_for_value(v, default: default) }) Regexp.union(value.map { |v| regexp_for_value(v, default: default) })
......
...@@ -24,8 +24,8 @@ module Gitlab ...@@ -24,8 +24,8 @@ module Gitlab
# link_json('specific_package', '1.0.1', link: :key) # link_json('specific_package', '1.0.1', link: :key)
# # Will link `specific_package` in `"specific_package": "1.0.1"` # # Will link `specific_package` in `"specific_package": "1.0.1"`
def link_json(key, value = nil, link: :value, &url_proc) def link_json(key, value = nil, link: :value, &url_proc)
key = regexp_for_value(key, default: /[^"]+/) key = regexp_for_value(key, default: /[^" ]+/)
value = regexp_for_value(value, default: /[^"]+/) value = regexp_for_value(value, default: /[^" ]+/)
if link == :value if link == :value
value = /(?<name>#{value})/ value = /(?<name>#{value})/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment