Commit 47de0107 authored by Stan Hu's avatar Stan Hu

Merge branch 'ajk-safe-wiki-event-url' into 'master'

Ensure we always generate a valid URL

Closes #220932

See merge request gitlab-org/gitlab!34191
parents 64896390 7a24d526
......@@ -188,7 +188,7 @@ module EventsHelper
end
def event_wiki_page_target_url(event)
project_wiki_url(event.project, event.target.canonical_slug)
project_wiki_url(event.project, event.target&.canonical_slug || Wiki::HOMEPAGE)
end
def event_note_title_html(event)
......
---
title: Ensure we always generate a valid wiki event URL
merge_request: 34191
author:
type: fixed
......@@ -150,6 +150,21 @@ describe EventsHelper do
expect(helper.event_wiki_page_target_url(event)).to eq(url)
end
context 'there is no canonical slug' do
let(:event) { create(:wiki_page_event, project: project) }
before do
event.target.slugs.update_all(canonical: false)
event.target.clear_memoization(:canonical_slug)
end
it 'links to the home page' do
url = helper.project_wiki_url(project, Wiki::HOMEPAGE)
expect(helper.event_wiki_page_target_url(event)).to eq(url)
end
end
end
describe '#event_wiki_title_html' do
......
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