|
70 | 70 |
|
71 | 71 | subject { described_class.parse_search_result(search_result) }
|
72 | 72 |
|
73 |
| - it 'can correctly parse filenames including ":"' do |
74 |
| - special_char_result = "\nmaster:testdata/project::function1.yaml-1----\nmaster:testdata/project::function1.yaml:2:test: data1\n" |
75 |
| - |
76 |
| - blob = described_class.parse_search_result(special_char_result) |
77 |
| - |
78 |
| - expect(blob.ref).to eq('master') |
79 |
| - expect(blob.filename).to eq('testdata/project::function1.yaml') |
80 |
| - end |
81 |
| - |
82 | 73 | it "returns a valid FoundBlob" do
|
83 | 74 | is_expected.to be_an Gitlab::SearchResults::FoundBlob
|
84 | 75 | expect(subject.id).to be_nil
|
|
90 | 81 | expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n")
|
91 | 82 | end
|
92 | 83 |
|
| 84 | + context 'when the matching filename contains a colon' do |
| 85 | + let(:search_result) { "\nmaster:testdata/project::function1.yaml\x001\x00---\n" } |
| 86 | + |
| 87 | + it 'returns a valid FoundBlob' do |
| 88 | + expect(subject.filename).to eq('testdata/project::function1.yaml') |
| 89 | + expect(subject.basename).to eq('testdata/project::function1') |
| 90 | + expect(subject.ref).to eq('master') |
| 91 | + expect(subject.startline).to eq(1) |
| 92 | + expect(subject.data).to eq('---') |
| 93 | + end |
| 94 | + end |
| 95 | + |
| 96 | + context 'when the matching content contains a number surrounded by colons' do |
| 97 | + let(:search_result) { "\nmaster:testdata/foo.txt\x001\x00blah:9:blah" } |
| 98 | + |
| 99 | + it 'returns a valid FoundBlob' do |
| 100 | + expect(subject.filename).to eq('testdata/foo.txt') |
| 101 | + expect(subject.basename).to eq('testdata/foo') |
| 102 | + expect(subject.ref).to eq('master') |
| 103 | + expect(subject.startline).to eq(1) |
| 104 | + expect(subject.data).to eq('blah:9:blah') |
| 105 | + end |
| 106 | + end |
| 107 | + |
93 | 108 | context "when filename has extension" do
|
94 |
| - let(:search_result) { "master:CONTRIBUTE.md:5:- [Contribute to GitLab](#contribute-to-gitlab)\n" } |
| 109 | + let(:search_result) { "master:CONTRIBUTE.md\x005\x00- [Contribute to GitLab](#contribute-to-gitlab)\n" } |
95 | 110 |
|
96 | 111 | it { expect(subject.path).to eq('CONTRIBUTE.md') }
|
97 | 112 | it { expect(subject.filename).to eq('CONTRIBUTE.md') }
|
98 | 113 | it { expect(subject.basename).to eq('CONTRIBUTE') }
|
99 | 114 | end
|
100 | 115 |
|
101 | 116 | context "when file under directory" do
|
102 |
| - let(:search_result) { "master:a/b/c.md:5:a b c\n" } |
| 117 | + let(:search_result) { "master:a/b/c.md\x005\x00a b c\n" } |
103 | 118 |
|
104 | 119 | it { expect(subject.path).to eq('a/b/c.md') }
|
105 | 120 | it { expect(subject.filename).to eq('a/b/c.md') }
|
|
144 | 159 | end
|
145 | 160 |
|
146 | 161 | it 'finds by content' do
|
147 |
| - expect(results).to include("master:Title.md:1:Content\n") |
| 162 | + expect(results).to include("master:Title.md\x001\x00Content\n") |
148 | 163 | end
|
149 | 164 | end
|
150 | 165 |
|
|
0 commit comments