Skip to content

Wiki editor trims leading and trailing whitespace, breaking formatting

Summary

When editing a wiki page, the first line's leading whitespace and the last line's trailing whitespace is (unexpectedly) trimmed, which sometimes breaks Markdown formatting.

Steps to reproduce

  • Go to a project's Wiki section and click "New page"
  • Enter this content:
       - item 1
       - item 2
    
    
    (That is, on the first line, three spaces followed by hyphen followed by text followed by a linebreak, and similar on the second line.)
  • Click "Create page"
  • It correctly creates a page with 2 items at the same indentation level — good
  • Click the Edit button
  • The Content field now shows this: — bad
    - item 1
       - item 2
    (That is, the leading spaces on the first line have been removed, and the linebreak following the second line has been removed.)
  • Without changing anything, click "Save changes"
  • The wiki page now shows the 2 items at different indentation levels — bad
  • Click "Page history" and click the "Changes" link for the most recent change
  • The changes page shows that the leading spaces on the first line have been removed, and that the linebreak following the second line has been removed — bad

Example Project

https://gitlab.com/smokris/wiki-edit-test/-/wikis/home/diff?version_id=cc84322f66b7ae01e8bb86118fe2cd8e93f9340b

What is the current bug behavior?

The first line's leading whitespace and the last line's trailing whitespace is trimmed.

What is the expected correct behavior?

If I click Edit then click "Save changes" without changing anything, the wiki text should remain exactly the same (the diff should be empty).

Relevant logs and/or screenshots

Screen_Shot_2021-05-27_at_9.49.48_AM

Output of checks

This bug happens on GitLab.com and on my self-hosted instance.

Possible fixes