summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-08 16:30:23 +0000
committerDouwe Maan <douwe@gitlab.com>2015-04-08 16:30:23 +0000
commitf3f856029bc5f966c5a7ee24cf7efefdd20e6019 (patch)
tree34440f1113b7d3acd005bafbcd67d4e2dbf09f28
parenta381ecbdbc3dbdbe7a0056cebc5cbf905af8e69c (diff)
parent3143edfea6b71a6a26470e3f4a9cffa773f584ec (diff)
downloadgitlab-ce-f3f856029bc5f966c5a7ee24cf7efefdd20e6019.tar.gz
Merge branch 'fix-slashes-in-wiki-urls' into 'master'
Fix bug where Wiki pages that include a '/' were no longer accessible ### What does this MR do? This MR fixes a regression that caused Wiki pages that included a '/' to no longer be accessible. ### Are there points in the code the reviewer needs to double check? Are there cases that `wiki_helper.rb` doesn't handle? ### Why was this MR needed? The upgrade from Rails v4.1.2 to v4.1.9 (76aad9b76ed) caused slashes in a model ID to be escaped automatically. We can no longer use the built-in the URL helpers to generate the links for Wiki pages if we want to maintain support for slashes. There is no option to tell the formatter otherwise: http://stackoverflow.com/questions/25031791/rails-4-1-2-to-param-escapes-slashes-and-breaks-app The Rails code in question is here: https://github.com/rails/rails/blob/4-1-stable/actionpack/lib/action_dispatch/journey/visitors.rb#L159 ### What are the relevant issue numbers / [Feature requests](http://feedback.gitlab.com/)? #1363 See merge request !502
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/projects/wikis_controller.rb6
-rw-r--r--app/helpers/wiki_helper.rb22
-rw-r--r--features/project/wiki.feature24
-rw-r--r--features/steps/project/wiki.rb36
5 files changed, 88 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3d4fcc11929..0878c03207b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Please view this file on the master branch, on stable branches it's out of date.
v 7.10.0 (unreleased)
+ - Fix bug where Wiki pages that included a '/' were no longer accessible (Stan Hu)
- Fix bug where error messages from Dropzone would not be displayed on the issues page (Stan Hu)
- Add ability to configure Reply-To address in gitlab.yml (Stan Hu)
- Fix broken side-by-side diff view on merge request page (Stan Hu)
diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb
index 643167947b9..aeb7f0699f5 100644
--- a/app/controllers/projects/wikis_controller.rb
+++ b/app/controllers/projects/wikis_controller.rb
@@ -5,6 +5,7 @@ class Projects::WikisController < Projects::ApplicationController
before_filter :authorize_write_wiki!, only: [:edit, :create, :history]
before_filter :authorize_admin_wiki!, only: :destroy
before_filter :load_project_wiki
+ include WikiHelper
def pages
@wiki_pages = Kaminari.paginate_array(@project_wiki.pages).page(params[:page]).per(PER_PAGE)
@@ -45,7 +46,10 @@ class Projects::WikisController < Projects::ApplicationController
return render('empty') unless can?(current_user, :write_wiki, @project)
if @page.update(content, format, message)
- redirect_to [@project.namespace.becomes(Namespace), @project, @page], notice: 'Wiki was successfully updated.'
+ redirect_to(
+ namespace_project_wiki_path(@project.namespace, @project, @page),
+ notice: 'Wiki was successfully updated.'
+ )
else
render 'edit'
end
diff --git a/app/helpers/wiki_helper.rb b/app/helpers/wiki_helper.rb
new file mode 100644
index 00000000000..a3bc64c010e
--- /dev/null
+++ b/app/helpers/wiki_helper.rb
@@ -0,0 +1,22 @@
+module WikiHelper
+ # Rails v4.1.9+ escapes all model IDs, converting slashes into %2F. The
+ # only way around this is to implement our own path generators.
+ def namespace_project_wiki_path(namespace, project, wiki_page, *args)
+ slug =
+ case wiki_page
+ when Symbol
+ wiki_page
+ else
+ wiki_page.slug
+ end
+ namespace_project_path(namespace, project) + "/wikis/#{slug}"
+ end
+
+ def edit_namespace_project_wiki_path(namespace, project, wiki_page, *args)
+ namespace_project_wiki_path(namespace, project, wiki_page) + '/edit'
+ end
+
+ def history_namespace_project_wiki_path(namespace, project, wiki_page, *args)
+ namespace_project_wiki_path(namespace, project, wiki_page) + '/history'
+ end
+end
diff --git a/features/project/wiki.feature b/features/project/wiki.feature
index 4a8c771ddac..977cd609a11 100644
--- a/features/project/wiki.feature
+++ b/features/project/wiki.feature
@@ -62,3 +62,27 @@ Feature: Project Wiki
And I browse to wiki page with images
And I click on image link
Then I should see the new wiki page form
+
+ @javascript
+ Scenario: New Wiki page that has a path
+ Given I create a New page with paths
+ And I click on the "Pages" button
+ Then I should see non-escaped link in the pages list
+
+ @javascript
+ Scenario: Edit Wiki page that has a path
+ Given I create a New page with paths
+ And I click on the "Pages" button
+ And I edit the Wiki page with a path
+ Then I should see a non-escaped path
+ And I should see the Editing page
+ And I change the content
+ Then I should see the updated content
+
+ @javascript
+ Scenario: View the page history of a Wiki page that has a path
+ Given I create a New page with paths
+ And I click on the "Pages" button
+ And I view the page history of a Wiki page that has a path
+ Then I should see a non-escaped path
+ And I should see the page history
diff --git a/features/steps/project/wiki.rb b/features/steps/project/wiki.rb
index cd7d5eac243..bb93e582a1f 100644
--- a/features/steps/project/wiki.rb
+++ b/features/steps/project/wiki.rb
@@ -3,6 +3,7 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
include SharedProject
include SharedNote
include SharedPaths
+ include WikiHelper
step 'I click on the Cancel button' do
within(:css, ".form-actions") do
@@ -123,6 +124,41 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
page.should have_content('Editing - image.jpg')
end
+ step 'I create a New page with paths' do
+ click_on 'New Page'
+ fill_in 'Page slug', with: 'one/two/three'
+ click_on 'Build'
+ fill_in "wiki_content", with: 'wiki content'
+ click_on "Create page"
+ current_path.should include 'one/two/three'
+ end
+
+ step 'I should see non-escaped link in the pages list' do
+ page.should have_xpath("//a[@href='/#{project.path_with_namespace}/wikis/one/two/three']")
+ end
+
+ step 'I edit the Wiki page with a path' do
+ click_on 'three'
+ click_on 'Edit'
+ end
+
+ step 'I should see a non-escaped path' do
+ current_path.should include 'one/two/three'
+ end
+
+ step 'I should see the Editing page' do
+ page.should have_content('Editing')
+ end
+
+ step 'I view the page history of a Wiki page that has a path' do
+ click_on 'three'
+ click_on 'Page History'
+ end
+
+ step 'I should see the page history' do
+ page.should have_content('History for')
+ end
+
def wiki
@project_wiki = ProjectWiki.new(project, current_user)
end