• Dmitriy Zaporozhets's avatar
    Merge branch 'fix-dots-in-wiki-title' into 'master' · 1d85e5ff
    Dmitriy Zaporozhets authored
    Fix dots in Wiki slug causing errors
    
    ### What does this MR do?
    
    When a user enters in dots into the Wiki slug, an error occurs:
    
    ```
    NoMethodError (undefined method `escaped_url_path' for nil:NilClass):
      app/models/wiki_page.rb:172:in `set_attributes'
      app/models/wiki_page.rb:191:in `save'
      app/models/wiki_page.rb:155:in `update'
      app/controllers/projects/wikis_controller.rb:49:in `update'
    ```
    
    This MR fixes this problem.
    
    ### Are there points in the code the reviewer needs to double check?
    
    See the problem below.
    
    ### Why was this MR needed?
    
    The issue is that the `save` method gets called differently:
    
    ```ruby
    def create(attr = {})
    ....
        save :create_page, title, content, format, message
    ```
    
    or
    
    ```ruby
    def update(new_content = "", format = :markdown, message = nil)
    ...
        save :update_page, @page, content, format, message
    ```
    
    In the create case, title is the slug entered in by the user (e.g. `path/how-to-write-wiki-pages`).
    
    In the update case, originally `@page.page` included the format extension (e.g.`path/how-to-write-wiki-pages.Markdown`). The method `page_title_and_dir` was trying to handle both cases and not doing the right thing. For example, calling `page_title_and_dir('test-1.2.3')` would result in:
    
    ```
    path_title = test-1.2
    path_dir = 3
    ```
    
    ### What are the relevant issue numbers / [Feature requests](http://feedback.gitlab.com/)?
    
    Issues #1263, #431
    
    This replaces !156
    
    See merge request !419
    1d85e5ff
To find the state of this project's repository at the time of any of these versions, check out the tags.
CHANGELOG 52.5 KB