Commit e25ddca0c462522703af93822863023f4a754390

Authored by Valeriy Sizov
1 parent 73d5e51a

Fix bug with branches whose name contains slash

lib/extracts_path.rb
... ... @@ -56,22 +56,22 @@ module ExtractsPath
56 56  
57 57 # Append a trailing slash if we only get a ref and no file path
58 58 id = input
59   - id += '/' unless id.include?('/')
60   -
  59 + id += '/' unless id.ends_with?('/')
  60 +
61 61 valid_refs = @project.branches + @project.tags
62   - valid_refs.select! { |v| id.start_with?("#{v}/") }
63   -
  62 + valid_refs.select! { |v| id.start_with?("#{v.name}/") }
  63 +
64 64 if valid_refs.length != 1
65 65 # No exact ref match, so just try our best
66 66 pair = id.match(/([^\/]+)(.*)/).captures
67 67 else
68 68 # Partition the string into the ref and the path, ignoring the empty first value
69   - pair = id.partition(valid_refs.first)[1..-1]
  69 + pair = id.partition(valid_refs.first.name)[1..-1]
70 70 end
71 71 end
72 72  
73   - # Remove leading slash from path
74   - pair[1].gsub!(/^\//, '')
  73 + # Remove ending slashes from path
  74 + pair[1].gsub!(/^\/|\/$/, '')
75 75  
76 76 pair
77 77 end
... ...
spec/lib/extracts_path_spec.rb
... ... @@ -7,8 +7,8 @@ describe ExtractsPath do
7 7  
8 8 before do
9 9 @project = project
10   - project.stub(:branches).and_return(['master', 'foo/bar/baz'])
11   - project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
  10 + project.stub(:branches).and_return([stub(name: 'master'), stub(name: 'foo/bar/baz')])
  11 + project.stub(:tags).and_return([stub(name: 'master'), stub(name: 'master')])
12 12 end
13 13  
14 14 describe '#extract_ref' do
... ...