Commit c280edd3 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix_wiki_links' into 'master'

Fix wiki search results point to raw source

Closes https://github.com/gitlabhq/gitlabhq/issues/9581

See merge request !3138
parents 6dad8640 f0b052e1
...@@ -11,6 +11,7 @@ v 8.6.0 (unreleased) ...@@ -11,6 +11,7 @@ v 8.6.0 (unreleased)
GitLab will ask the user to create a new one upon first visit. GitLab will ask the user to create a new one upon first visit.
- Fix issue when pushing to projects ending in .wiki - Fix issue when pushing to projects ending in .wiki
- Add support for wiki with UTF-8 page names (Hiroyuki Sato) - Add support for wiki with UTF-8 page names (Hiroyuki Sato)
- Fix wiki search results point to raw source (Hiroyuki Sato)
- Don't load all of GitLab in mail_room - Don't load all of GitLab in mail_room
- Update `omniauth-saml` to 1.5.0 to allow for custom response attributes to be set - Update `omniauth-saml` to 1.5.0 to allow for custom response attributes to be set
- Memoize @group in Admin::GroupsController (Yatish Mehta) - Memoize @group in Admin::GroupsController (Yatish Mehta)
......
...@@ -758,12 +758,15 @@ class Repository ...@@ -758,12 +758,15 @@ class Repository
def parse_search_result(result) def parse_search_result(result)
ref = nil ref = nil
filename = nil filename = nil
basename = nil
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+:/ if line =~ /^.*:.*:\d+:/
ref, filename, startline = line.split(':') ref, filename, startline = line.split(':')
startline = startline.to_i - index startline = startline.to_i - index
extname = File.extname(filename)
basename = filename.sub(/#{extname}$/, '')
break break
end end
end end
...@@ -776,6 +779,7 @@ class Repository ...@@ -776,6 +779,7 @@ class Repository
OpenStruct.new( OpenStruct.new(
filename: filename, filename: filename,
basename: basename,
ref: ref, ref: ref,
startline: startline, startline: startline,
data: data data: data
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
.blob-result .blob-result
.file-holder .file-holder
.file-title .file-title
= link_to namespace_project_wiki_path(@project.namespace, @project, wiki_blob.filename) do = link_to namespace_project_wiki_path(@project.namespace, @project, wiki_blob.basename) do
%i.fa.fa-file %i.fa.fa-file
%strong %strong
= wiki_blob.filename = wiki_blob.basename
.file-content.code.term .file-content.code.term
= render 'shared/file_highlight', blob: wiki_blob, first_line_number: wiki_blob.startline = render 'shared/file_highlight', blob: wiki_blob, first_line_number: wiki_blob.startline
...@@ -100,7 +100,7 @@ class Spinach::Features::Search < Spinach::FeatureSteps ...@@ -100,7 +100,7 @@ class Spinach::Features::Search < Spinach::FeatureSteps
step 'I should see "test_wiki" link in the search results' do step 'I should see "test_wiki" link in the search results' do
page.within('.results') do page.within('.results') do
find(:css, '.search-results').should have_link 'test_wiki.md' expect(find(:css, '.search-results')).to have_link 'test_wiki'
end end
end end
......
...@@ -101,13 +101,29 @@ describe Repository, models: true do ...@@ -101,13 +101,29 @@ describe Repository, models: true do
end end
describe 'parsing result' do describe 'parsing result' do
subject { repository.parse_search_result(results.first) } subject { repository.parse_search_result(search_result) }
let(:search_result) { results.first }
it { is_expected.to be_an OpenStruct } it { is_expected.to be_an OpenStruct }
it { expect(subject.filename).to eq('CHANGELOG') } it { expect(subject.filename).to eq('CHANGELOG') }
it { expect(subject.basename).to eq('CHANGELOG') }
it { expect(subject.ref).to eq('master') } it { expect(subject.ref).to eq('master') }
it { expect(subject.startline).to eq(186) } it { expect(subject.startline).to eq(186) }
it { expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n") } it { expect(subject.data.lines[2]).to eq(" - Feature: Replace teams with group membership\n") }
context "when filename has extension" do
let(:search_result) { "master:CONTRIBUTE.md:5:- [Contribute to GitLab](#contribute-to-gitlab)\n" }
it { expect(subject.filename).to eq('CONTRIBUTE.md') }
it { expect(subject.basename).to eq('CONTRIBUTE') }
end
context "when file under directory" do
let(:search_result) { "master:a/b/c.md:5:a b c\n" }
it { expect(subject.filename).to eq('a/b/c.md') }
it { expect(subject.basename).to eq('a/b/c') }
end
end end
end end
......
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