fix for special charecter in file names
This commit is contained in:
parent
73e48b745c
commit
869877ab26
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
title: Fix search results when a filename would contain a special character.
|
||||||
|
merge_request: 15606
|
||||||
|
author: haseebeqx
|
||||||
|
type: fixed
|
|
@ -47,8 +47,11 @@ module Gitlab
|
||||||
startline = 0
|
startline = 0
|
||||||
|
|
||||||
result.each_line.each_with_index do |line, index|
|
result.each_line.each_with_index do |line, index|
|
||||||
if line =~ /^.*:.*:\d+:/
|
matches = line.match(/^(?<ref>[^:]*):(?<filename>.*):(?<startline>\d+):/)
|
||||||
ref, filename, startline = line.split(':')
|
if matches
|
||||||
|
ref = matches[:ref]
|
||||||
|
filename = matches[:filename]
|
||||||
|
startline = matches[:startline]
|
||||||
startline = startline.to_i - index
|
startline = startline.to_i - index
|
||||||
extname = Regexp.escape(File.extname(filename))
|
extname = Regexp.escape(File.extname(filename))
|
||||||
basename = filename.sub(/#{extname}$/, '')
|
basename = filename.sub(/#{extname}$/, '')
|
||||||
|
|
|
@ -70,6 +70,15 @@ describe Gitlab::ProjectSearchResults do
|
||||||
|
|
||||||
subject { described_class.parse_search_result(search_result) }
|
subject { described_class.parse_search_result(search_result) }
|
||||||
|
|
||||||
|
it 'can correctly parse filenames including ":"' do
|
||||||
|
special_char_result = "\nmaster:testdata/project::function1.yaml-1----\nmaster:testdata/project::function1.yaml:2:test: data1\n"
|
||||||
|
|
||||||
|
blob = described_class.parse_search_result(special_char_result)
|
||||||
|
|
||||||
|
expect(blob.ref).to eq('master')
|
||||||
|
expect(blob.filename).to eq('testdata/project::function1.yaml')
|
||||||
|
end
|
||||||
|
|
||||||
it "returns a valid FoundBlob" do
|
it "returns a valid FoundBlob" do
|
||||||
is_expected.to be_an Gitlab::SearchResults::FoundBlob
|
is_expected.to be_an Gitlab::SearchResults::FoundBlob
|
||||||
expect(subject.id).to be_nil
|
expect(subject.id).to be_nil
|
||||||
|
|
Loading…
Reference in New Issue