Skip to content
Snippets Groups Projects
Commit 91f8656c authored by Jan Provaznik's avatar Jan Provaznik Committed by Rémy Coutable
Browse files

Disable greedy mode when matching filename

parent a78b1b27
No related branches found
No related tags found
No related merge requests found
---
title: Fix filename matching when processing file or blob search results
merge_request:
author:
type: fixed
Loading
Loading
@@ -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]
Loading
Loading
Loading
Loading
@@ -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
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment