View Issue Details

IDProjectCategoryView StatusLast Update
0025839mantisbthtmlpublic2019-11-13 12:19
ReporterTomekAP Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version2.21.0 
Target Version2.22.0Fixed in Version2.22.0 
Summary0025839: Leading newlines disappear when editing data in textarea elements
Description

if you write in e.g. steps_to_reproduce:
new line at the begining, this new line wouldn`t be shown while editing. View is OK.
If you have n new lines at the begining, while editing n-1 new line would be shown.

Example:
<textarea class="form-control" tabindex="14" cols="80" rows="10" id="steps_to_reproduce" name="steps_to_reproduce">

3

5</textarea>

TagsNo tags attached.
Attached Files

Relationships

related to 0026351 closeddregad Field "EXCEL columns" has space or tabulation 

Activities

dregad

dregad

2019-06-05 04:49

developer   ~0062197

Not sure I understand what you mean. We trim whitespace prior to saving, so any leading newlines would be removed, this is normal and expected behavior.

TomekAP

TomekAP

2019-06-05 05:20

reporter   ~0062202

I have tested it on 2.21
in steps to reproduce write:
new line (enter)
new line (enter)
3

5
in view page you see:
new line (enter)
new line (enter)
3

5
it is OK, but if you edit now this page, you will see in textarea:
new line (enter)
3

5

so the first new line is missing.
Have you tested it?

dregad

dregad

2019-06-05 09:40

developer   ~0062206

OK, I see what you mean now. Looks like Mantis is somehow removing a single newline from the text, each time the issue is updated.

What confused me was

in view page you see:
new line (enter)
new line (enter)
3

But in fact in view issue page (view.php) you there are no leading newlines at all (as shown in attached screensot).

screenshot-20190605-1529.png (1,428 bytes)   
screenshot-20190605-1529.png (1,428 bytes)   
TomekAP

TomekAP

2019-06-05 09:51

reporter   ~0062208

So on our mantis new line at the beginning is not removed and is stored with new lines in DB.
Could you check, where in code it is being removed?
I can not edit here an issue, so cannot check it.

dregad

dregad

2019-06-05 11:47

developer   ~0062211

The newlines are stored in the DB exactly as you typed them when you click the Submit / Update button. They are only hidden on display (due to the fact that HTML ignores whitespace).

The behavior you're experiencing is a consequence of the HTML5 specification (look under A start tag whose tag name is "textarea" , emphasis mine):

If the next token is a U+000A LINE FEED (LF) character token, then ignore that token and move on to the next one. (Newlines at the start of textarea elements are ignored as an authoring convenience.)

To fix this, we'd have to update the markup everywhere we use textareas, to add a newline after the opening tag.

dregad

dregad

2019-06-05 12:45

developer   ~0062212

Please see PR https://github.com/mantisbt/mantisbt/pull/1518

Kindly test and let me know your feedback, either here or in the PR.

TomekAP

TomekAP

2019-06-05 15:59

reporter   ~0062213

As for me, it is OK, but wouldn`t be better to change it in the string_textarea function?

dregad

dregad

2019-06-06 05:40

developer   ~0062217

Thanks for the feedback.

wouldn`t be better to change it in the string_textarea function

string_textarea() deals with display, so I don't think modifying it would be the right way to fix this issue.

The problem as I see it, is about storage : MantisBT should not alter data (i.e. text should be stored exactly as the user entered it). Currently due to the behavior defined by HTML 5 spec, we are removing one newline every time a textarea is edited and then saved, until there are no more. That's what I covered in the PR.

vboctor

vboctor

2019-06-11 02:16

manager   ~0062235

I would expect that the behavior should be to trim text box and text area values before adding them to the database. This would make view and edit behavior consistent, while removing extra blank lines before/after text.

atrol

atrol

2019-06-11 17:18

developer   ~0062241

the behavior should be to trim text box and text area values before adding them to the database.

This would mean we have also to trim data entered via SOAP or REST API (hardly a good idea).
If not, we will still have the issue, that interactive editing an issue without changing anything, will change data and create history entries in some cases because

we are removing one newline every time a textarea is edited and then saved, until there are no more

so +1 for

MantisBT should not alter data (i.e. text should be stored exactly as the user entered it)

Related Changesets

MantisBT: master d975045e

2019-06-05 08:40

dregad


Details Diff
Add newline after <textarea> tags

The HTML 5 specification states that "Newlines at the start of textarea
elements are ignored as an authoring convenience." [1]

To avoid altering user data (e.g. issue description, steps to reproduce,
etc.) having leading newline(s) when editing and saving, the markup of
all pages displaying user content in textarea tags has been modified to
add a newline after the opening tag.

Fixes 0025839

[1]: https://www.w3.org/TR/html52/syntax.html#the-in-body-insertion-mode
Affected Issues
0025839, 0026351
mod - account_prof_edit_page.php Diff File
mod - bug_report_page.php Diff File
mod - bug_update_page.php Diff File
mod - manage_columns_inc.php Diff File
mod - manage_custom_field_edit_page.php Diff File
mod - manage_proj_edit_page.php Diff File
mod - manage_proj_ver_edit_page.php Diff File
mod - news_edit_page.php Diff File
mod - proj_doc_edit_page.php Diff File
mod - tag_update_page.php Diff File

MantisBT: master-2.22 9b0dce28

2019-11-13 07:09

dregad


Details Diff
Remove unwanted whitespace in Excel columns textarea

Regression introduced by d975045e9a30d253a21662a9c14868ef63f5b5c7.

Fixes 0026351
Affected Issues
0025839, 0026351
mod - manage_columns_inc.php Diff File