GitLab steht wegen Wartungsarbeiten am Montag, den 10. Mai, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit b16aad9d authored by Jeroen van Baarsen's avatar Jeroen van Baarsen

Validate wiki page creation

**What does this do?**
It adds validation to the creation of a wiki page, that way the user gets real
feedback instead of just a 404 page if the name of the wiki page was invalid

**Why is this needed?**
There are a lot of characters that are not allowed in the creation of a wiki
page, there is even a small text that is saying: Please don't use spaces.
Although we have that text there, we don't actually validate on this. This
commit adds validation on the title and gives the user actual feedback.

**What issues does this fix?**
Fixes http://github.com/gitlabhq/gitlabhq/issues/5357
Fixes https://github.com/gitlabhq/gitlabhq/issues/8565
Fixes https://github.com/gitlabhq/gitlabhq/issues/3913
Fixes https://github.com/gitlabhq/gitlabhq/issues/8166Signed-off-by: default avatarJeroen van Baarsen <jeroenvanbaarsen@gmail.com>
parent b6117074
...@@ -11,6 +11,7 @@ v 7.12.0 (unreleased) ...@@ -11,6 +11,7 @@ v 7.12.0 (unreleased)
- Fix resolving of relative links to repository files in AsciiDoc documents. (Jakub Jirutka) - Fix resolving of relative links to repository files in AsciiDoc documents. (Jakub Jirutka)
- Use the user list from the target project in a merge request (Stan Hu) - Use the user list from the target project in a merge request (Stan Hu)
- Default extention for wiki pages is now .md instead of .markdown (Jeroen van Baarsen) - Default extention for wiki pages is now .md instead of .markdown (Jeroen van Baarsen)
- Add validation to wiki page creation (only [a-zA-Z0-9/_-] are allowed) (Jeroen van Baarsen)
v 7.11.2 v 7.11.2
- no changes - no changes
......
class @Wikis class @Wikis
constructor: -> constructor: ->
$('.build-new-wiki').bind "click", -> $('.build-new-wiki').bind "click", (e) ->
$('[data-error~=slug]').addClass("hidden")
$('p.hint').show()
field = $('#new_wiki_path') field = $('#new_wiki_path')
slug = field.val() valid_slug_pattern = /^[\w\/-]+$/
path = field.attr('data-wikis-path')
if(slug.length > 0) slug = field.val()
location.href = path + "/" + slug if slug.match valid_slug_pattern
path = field.attr('data-wikis-path')
if(slug.length > 0)
location.href = path + "/" + slug
else
e.preventDefault()
$('p.hint').hide()
$('[data-error~=slug]').removeClass("hidden")
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
= label_tag :new_wiki_path do = label_tag :new_wiki_path do
%span Page slug %span Page slug
= text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'form-control', required: true, :'data-wikis-path' => namespace_project_wikis_path(@project.namespace, @project) = text_field_tag :new_wiki_path, nil, placeholder: 'how-to-setup', class: 'form-control', required: true, :'data-wikis-path' => namespace_project_wikis_path(@project.namespace, @project)
%p.hidden.text-danger{data: { error: "slug" }}
The page slug is invalid. Please don't use characters other then: a-z 0-9 _ - and /
%p.hint %p.hint
Please don't use spaces. Please don't use spaces.
.modal-footer .modal-footer
......
...@@ -69,6 +69,11 @@ Feature: Project Wiki ...@@ -69,6 +69,11 @@ Feature: Project Wiki
And I click on the "Pages" button And I click on the "Pages" button
Then I should see non-escaped link in the pages list Then I should see non-escaped link in the pages list
@javascript @focus
Scenario: Creating an invalid new page
Given I create a New page with an invalid name
Then I should see an error message
@javascript @javascript
Scenario: Edit Wiki page that has a path Scenario: Edit Wiki page that has a path
Given I create a New page with paths Given I create a New page with paths
......
...@@ -133,6 +133,16 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps ...@@ -133,6 +133,16 @@ class Spinach::Features::ProjectWiki < Spinach::FeatureSteps
current_path.should include 'one/two/three' current_path.should include 'one/two/three'
end end
step 'I create a New page with an invalid name' do
click_on 'New Page'
fill_in 'Page slug', with: 'invalid name'
click_on 'Build'
end
step 'I should see an error message' do
expect(page).to have_content "The page slug is invalid"
end
step 'I should see non-escaped link in the pages list' do 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']") page.should have_xpath("//a[@href='/#{project.path_with_namespace}/wikis/one/two/three']")
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