Commit 6eb00b13 authored by Markus Koller's avatar Markus Koller

Fix WikiPage#title_changed for paths with spaces

If a wiki page is inside a directory with spaces, the change detection
didn't account for hyphenated spaces and mistakenly assumed the title
was changed when it wasn't, causing a validation error.

This also fixes the specs to catch this case.
parent b815e6f6
...@@ -257,7 +257,7 @@ class WikiPage ...@@ -257,7 +257,7 @@ 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)) old_title, old_dir = wiki.page_title_and_dir(self.class.unhyphenize(@page.url_path))
new_title, new_dir = wiki.page_title_and_dir(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)
else else
......
---
title: Fix WikiPage#title_changed for paths with spaces
merge_request: 27087
author:
type: fixed
...@@ -480,8 +480,8 @@ describe WikiPage do ...@@ -480,8 +480,8 @@ describe WikiPage do
let(:untitled_page) { described_class.new(wiki) } let(:untitled_page) { described_class.new(wiki) }
let(:directory_page) do let(:directory_page) do
create_page('parent/child', 'test content') create_page('parent directory/child page', 'test content')
wiki.find_page('parent/child') wiki.find_page('parent directory/child page')
end end
where(:page, :title, :changed) do where(:page, :title, :changed) do
...@@ -494,15 +494,25 @@ describe WikiPage do ...@@ -494,15 +494,25 @@ describe WikiPage do
:existing_page | nil | false :existing_page | nil | 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' | false
:existing_page | ' test page ' | true
:existing_page | 'new title' | true :existing_page | 'new title' | true
:existing_page | 'new-title' | true
:directory_page | nil | false :directory_page | nil | false
:directory_page | 'parent/child' | false :directory_page | 'parent directory/child page' | false
:directory_page | 'child' | false :directory_page | 'parent-directory/child page' | false
:directory_page | '/child' | true :directory_page | 'parent-directory/child-page' | false
:directory_page | 'parent/other' | true :directory_page | 'child page' | false
:directory_page | 'other/child' | true :directory_page | 'child-page' | false
:directory_page | '/child page' | true
:directory_page | 'parent directory/other' | true
:directory_page | 'parent-directory/other' | true
:directory_page | 'parent-directory / child-page' | true
:directory_page | 'other directory/child page' | true
:directory_page | 'other-directory/child 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