BigW Consortium Gitlab

Commit 0030fe53 by Rémy Coutable

Merge branch 'fix-wiki-error-500' into 'master'

Fix Error 500 when creating Wiki pages with hyphens or spaces - Closes gitlab-com/support-forum#874 - Closes #20209 See merge request !5444
parents 1b6de302 42a00f74
......@@ -9,6 +9,7 @@ v 8.11.0 (unreleased)
v 8.10.1 (unreleased)
- Fix bug where replies to commit notes displayed in the MR discussion tab wouldn't show up on the commit page
- Fix Error 500 when creating Wiki pages with hyphens or spaces
v 8.10.0
- Fix profile activity heatmap to show correct day name (eanplatter)
......
......@@ -44,7 +44,11 @@ class WikiPage
# The escaped URL path of this page.
def slug
@attributes[:slug]
if @attributes[:slug].present?
@attributes[:slug]
else
wiki.wiki.preview_page(title, '', format).url_path
end
end
alias_method :to_param, :slug
......
......@@ -6,7 +6,7 @@
- content_for :scripts_body_top do
- project = @target_project || @project
- if @project_wiki && @page
- markdown_preview_path = namespace_project_wiki_markdown_preview_path(project.namespace, project, @page.title)
- markdown_preview_path = namespace_project_wiki_markdown_preview_path(project.namespace, project, @page.slug)
- else
- markdown_preview_path = markdown_preview_namespace_project_path(project.namespace, project)
- if current_user
......
......@@ -130,15 +130,15 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
step 'I create a New page with paths' do
click_on 'New Page'
fill_in 'Page slug', with: 'one/two/three'
fill_in 'Page slug', with: 'one/two/three-test'
click_on 'Create Page'
fill_in "wiki_content", with: 'wiki content'
click_on "Create page"
expect(current_path).to include 'one/two/three'
expect(current_path).to include 'one/two/three-test'
end
step 'I should see non-escaped link in the pages list' do
expect(page).to have_xpath("//a[@href='/#{project.path_with_namespace}/wikis/one/two/three']")
expect(page).to have_xpath("//a[@href='/#{project.path_with_namespace}/wikis/one/two/three-test']")
end
step 'I edit the Wiki page with a path' do
......@@ -147,7 +147,7 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
end
step 'I should see a non-escaped path' do
expect(current_path).to include 'one/two/three'
expect(current_path).to include 'one/two/three-test'
end
step 'I should see the Editing page' do
......
require 'spec_helper'
feature 'Projects > Wiki > User previews markdown changes', feature: true, js: true do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
let(:wiki_content) do
<<-HEREDOC
[regular link](regular)
[relative link 1](../relative)
[relative link 2](./relative)
[relative link 3](./e/f/relative)
HEREDOC
end
background do
project.team << [user, :master]
login_as(user)
visit namespace_project_path(project.namespace, project)
click_link 'Wiki'
WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute
end
context "while creating a new wiki page" do
context "when there are no spaces or hyphens in the page name" do
it "rewrites relative links as expected" do
click_link 'New Page'
fill_in :new_wiki_path, with: 'a/b/c/d'
click_button 'Create Page'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/c/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
end
end
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
click_link 'New Page'
fill_in :new_wiki_path, with: 'a page/b page/c page/d page'
click_button 'Create Page'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
end
end
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
click_link 'New Page'
fill_in :new_wiki_path, with: 'a-page/b-page/c-page/d-page'
click_button 'Create Page'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
end
end
end
context "while editing a wiki page" do
def create_wiki_page(path)
click_link 'New Page'
fill_in :new_wiki_path, with: path
click_button 'Create Page'
fill_in :wiki_content, with: 'content'
click_on "Create page"
end
context "when there are no spaces or hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page 'a/b/c/d'
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/c/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a/b/c/e/f/relative\">relative link 3</a>")
end
end
context "when there are spaces in the page name" do
it "rewrites relative links as expected" do
create_wiki_page 'a page/b page/c page/d page'
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
end
end
context "when there are hyphens in the page name" do
it "rewrites relative links as expected" do
create_wiki_page 'a-page/b-page/c-page/d-page'
click_link 'Edit'
fill_in :wiki_content, with: wiki_content
click_on "Preview"
expect(page).to have_content("regular link")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/regular\">regular link</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/relative\">relative link 1</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>")
expect(page.html).to include("<a href=\"/#{project.path_with_namespace}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>")
end
end
end
end
......@@ -30,18 +30,48 @@ feature 'Projects > Wiki > User creates wiki page', feature: true do
WikiPages::CreateService.new(project, user, title: 'home', content: 'Home page').execute
end
scenario 'via the "new wiki page" page', js: true do
click_link 'New Page'
context 'via the "new wiki page" page' do
scenario 'when the wiki page has a single word name', js: true do
click_link 'New Page'
fill_in :new_wiki_path, with: 'foo'
click_button 'Create Page'
fill_in :new_wiki_path, with: 'foo'
click_button 'Create Page'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Create page'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Create page'
expect(page).to have_content('Foo')
expect(page).to have_content("last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
expect(page).to have_content('Foo')
expect(page).to have_content("last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
end
scenario 'when the wiki page has spaces in the name', js: true do
click_link 'New Page'
fill_in :new_wiki_path, with: 'Spaces in the name'
click_button 'Create Page'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Create page'
expect(page).to have_content('Spaces in the name')
expect(page).to have_content("last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
end
scenario 'when the wiki page has hyphens in the name', js: true do
click_link 'New Page'
fill_in :new_wiki_path, with: 'hyphens-in-the-name'
click_button 'Create Page'
fill_in :wiki_content, with: 'My awesome wiki!'
click_button 'Create page'
expect(page).to have_content('Hyphens in the name')
expect(page).to have_content("last edited by #{user.name}")
expect(page).to have_content('My awesome wiki!')
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