diff options
| author | Douwe Maan <douwe@gitlab.com> | 2015-04-08 16:30:23 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2015-04-08 16:30:23 +0000 |
| commit | f3f856029bc5f966c5a7ee24cf7efefdd20e6019 (patch) | |
| tree | 34440f1113b7d3acd005bafbcd67d4e2dbf09f28 /app | |
| parent | a381ecbdbc3dbdbe7a0056cebc5cbf905af8e69c (diff) | |
| parent | 3143edfea6b71a6a26470e3f4a9cffa773f584ec (diff) | |
| download | gitlab-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
Diffstat (limited to 'app')
| -rw-r--r-- | app/controllers/projects/wikis_controller.rb | 6 | ||||
| -rw-r--r-- | app/helpers/wiki_helper.rb | 22 |
2 files changed, 27 insertions, 1 deletions
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 |
