Commit f09ca0b8 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '218230-bugfix-save-wiki-page-modifications-with-certain-characters' into 'master'

Allow wiki pages with +<> characters in title to be saved

See merge request gitlab-org/gitlab!33803
parents 561c76d9 c5e06350
...@@ -271,7 +271,10 @@ class WikiPage ...@@ -271,7 +271,10 @@ class WikiPage
def title_changed? def title_changed?
if persisted? if persisted?
old_title, old_dir = wiki.page_title_and_dir(self.class.unhyphenize(page.url_path)) # A page's `title` will be returned from Gollum/Gitaly with any +<>
# characters changed to -, whereas the `path` preserves these characters.
path_without_extension = Pathname(page.path).sub_ext('').to_s
old_title, old_dir = wiki.page_title_and_dir(self.class.unhyphenize(path_without_extension))
new_title, new_dir = wiki.page_title_and_dir(self.class.unhyphenize(title)) new_title, new_dir = wiki.page_title_and_dir(self.class.unhyphenize(title))
new_title != old_title || (title.include?('/') && new_dir != old_dir) new_title != old_title || (title.include?('/') && new_dir != old_dir)
......
---
title: Allow wiki pages with +<> characters in their title to be saved
merge_request: 33803
author:
type: fixed
...@@ -651,6 +651,7 @@ describe WikiPage do ...@@ -651,6 +651,7 @@ describe WikiPage do
let(:untitled_page) { described_class.new(wiki) } let(:untitled_page) { described_class.new(wiki) }
let(:directory_page) { create(:wiki_page, title: 'parent directory/child page') } let(:directory_page) { create(:wiki_page, title: 'parent directory/child page') }
let(:page_with_special_characters) { create(:wiki_page, title: 'test+page') }
where(:page, :title, :changed) do where(:page, :title, :changed) do
:untitled_page | nil | false :untitled_page | nil | false
...@@ -658,6 +659,8 @@ describe WikiPage do ...@@ -658,6 +659,8 @@ describe WikiPage do
:new_page | nil | true :new_page | nil | true
:new_page | 'test page' | true :new_page | 'test page' | true
:new_page | 'test-page' | true
:new_page | 'test+page' | true
:new_page | 'new title' | true :new_page | 'new title' | true
:existing_page | nil | false :existing_page | nil | false
...@@ -665,6 +668,7 @@ describe WikiPage do ...@@ -665,6 +668,7 @@ describe WikiPage do
:existing_page | 'test-page' | false :existing_page | 'test-page' | false
:existing_page | '/test page' | false :existing_page | '/test page' | false
:existing_page | '/test-page' | false :existing_page | '/test-page' | false
:existing_page | 'test+page' | true
:existing_page | ' test page ' | true :existing_page | ' test page ' | true
:existing_page | 'new title' | true :existing_page | 'new title' | true
:existing_page | 'new-title' | true :existing_page | 'new-title' | true
...@@ -681,6 +685,11 @@ describe WikiPage do ...@@ -681,6 +685,11 @@ describe WikiPage do
:directory_page | 'parent-directory / child-page' | true :directory_page | 'parent-directory / child-page' | true
:directory_page | 'other directory/child page' | true :directory_page | 'other directory/child page' | true
:directory_page | 'other-directory/child page' | true :directory_page | 'other-directory/child page' | true
:page_with_special_characters | nil | false
:page_with_special_characters | 'test+page' | false
:page_with_special_characters | 'test-page' | true
:page_with_special_characters | 'test page' | true
end end
with_them do with_them 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