BigW Consortium Gitlab

Commit 91f8656c by Jan Provaznik Committed by Rémy Coutable

Disable greedy mode when matching filename

parent a78b1b27
---
title: Fix filename matching when processing file or blob search results
merge_request:
author:
type: fixed
...@@ -59,7 +59,7 @@ module Gitlab ...@@ -59,7 +59,7 @@ module Gitlab
startline = 0 startline = 0
result.each_line.each_with_index do |line, index| 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] ref = matches[:ref]
filename = matches[:filename] filename = matches[:filename]
startline = matches[:startline] startline = matches[:startline]
......
...@@ -106,6 +106,18 @@ describe Gitlab::ProjectSearchResults do ...@@ -106,6 +106,18 @@ describe Gitlab::ProjectSearchResults do
end end
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 context 'when the search result ends with an empty line' do
let(:results) { project.repository.search_files_by_content('Role models', 'master') } let(:results) { project.repository.search_files_by_content('Role models', 'master') }
......
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