Commit 84b022a5 authored by Sean McGivern's avatar Sean McGivern

Fix Repository#has_ambiguous_refs? regex

This regex intended to check if any refs that do not contain a slash
were a prefix of a ref containing the slash, plus the slash. That is:
`abc` is a prefix of `abc/def`, but not of `abcd/ef`.

However, the regex grouping was incorrect, and we were creating a regex
like `%r{^abc|def/}`, which doesn't contain parentheses, and so would
actually match plain `abc` (it wouldn't match `def/`).
parent ea81ac85
...@@ -214,7 +214,7 @@ class Repository ...@@ -214,7 +214,7 @@ class Repository
return false if with_slash.empty? return false if with_slash.empty?
prefixes = no_slash.map { |ref| Regexp.escape(ref) }.join('|') prefixes = no_slash.map { |ref| Regexp.escape(ref) }.join('|')
prefix_regex = %r{^#{prefixes}/} prefix_regex = %r{^(#{prefixes})/}
with_slash.any? do |ref| with_slash.any? do |ref|
prefix_regex.match?(ref) prefix_regex.match?(ref)
......
...@@ -1263,6 +1263,7 @@ RSpec.describe Repository do ...@@ -1263,6 +1263,7 @@ RSpec.describe Repository do
%w(a b c/z) | %w(c d) | true %w(a b c/z) | %w(c d) | true
%w(a/b/z) | %w(a/b) | false # we only consider refs ambiguous before the first slash %w(a/b/z) | %w(a/b) | false # we only consider refs ambiguous before the first slash
%w(a/b/z) | %w(a/b a) | true %w(a/b/z) | %w(a/b a) | true
%w(ab) | %w(abc/d a b) | false
end end
with_them do with_them do
......
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