Disable greedy mode when matching filename
This commit is contained in:
parent
a78b1b27b8
commit
91f8656c2c
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
title: Fix filename matching when processing file or blob search results
|
||||
merge_request:
|
||||
author:
|
||||
type: fixed
|
|
@ -59,7 +59,7 @@ module Gitlab
|
|||
startline = 0
|
||||
|
||||
result.each_line.each_with_index do |line, index|
|
||||
prefix ||= line.match(/^(?<ref>[^:]*):(?<filename>.*)\x00(?<startline>\d+)\x00/)&.tap do |matches|
|
||||
prefix ||= line.match(/^(?<ref>[^:]*):(?<filename>[^\x00]*)\x00(?<startline>\d+)\x00/)&.tap do |matches|
|
||||
ref = matches[:ref]
|
||||
filename = matches[:filename]
|
||||
startline = matches[:startline]
|
||||
|
|
|
@ -106,6 +106,18 @@ describe Gitlab::ProjectSearchResults do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when the matching content contains multiple null bytes' do
|
||||
let(:search_result) { "master:testdata/foo.txt\x001\x00blah\x001\x00foo" }
|
||||
|
||||
it 'returns a valid FoundBlob' do
|
||||
expect(subject.filename).to eq('testdata/foo.txt')
|
||||
expect(subject.basename).to eq('testdata/foo')
|
||||
expect(subject.ref).to eq('master')
|
||||
expect(subject.startline).to eq(1)
|
||||
expect(subject.data).to eq("blah\x001\x00foo")
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the search result ends with an empty line' do
|
||||
let(:results) { project.repository.search_files_by_content('Role models', 'master') }
|
||||
|
||||
|
|
Loading…
Reference in New Issue