87217[BUGFIX] Preserve correct line breaks in `<textarea>`
Commit message
Review
-
Code review CR +2 Done
- Benjamin Franzke +2
- Christian Kuhn +1
-
Verified V +2 Done
- Benjamin Franzke +2
- Riccardo De Contardi +1
- Christian Kuhn +1
- core-ci +1 CI
Issues 1
Files 4
Review log 3544
Show 1419 earlier messages
-
Albrecht Köhnlein uploaded patch set 1 11/23/24, 19:48
-
Albrecht Köhnlein updated the commit message in patch set 2 11/23/24, 19:51
-
core-ci voted on patch set 1 V +1 11/23/24, 19:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70088
-
core-ci voted on patch set 2 V +1 11/23/24, 20:00 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70089
-
Albrecht Köhnlein rebased onto patch set 3
V +112/11/24, 23:04 -
Benni Mack voted on patch set 3 CR +1 12/11/24, 23:05
-
core-ci voted on patch set 3 V +1 12/11/24, 23:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/70988
-
Christian Kuhn commented on patch set 3 12/12/24, 10:57
Hmm. We may want to get to the bottom of this: I would guess the true reason for all this fuzz with linebreaks in textarea fields is broken parsing on either js, or server side, or both: When sending form textarea data with multipart/form-data (standard formengine is multipart/form-data, other areas may use application/x-www-form-urlencoded, may need checks), browsers transfer linebreaks as CRLF, according to html specs: https://html.spec.whatwg.org/#multipart/form-data-encoding-algorithm " Replace every occurrence of U+000D (CR) not followed by U+000A (LF), and every occurrence of U+000A (LF) not preceded by U+000D (CR), in value, by a string consisting of U+000D (CR) and U+000A (LF). " -> line breaks are sent as CRLF (\r\n) to the server. Note this is "since ever", and we can be pretty much very certain every browser out there sticks to this. This is what involved code (for instance client side JS processing like in table-wizard-element), and server side processing should be checked for: If they tamper with linebreaks and don't expect CRLF. If there is code that for instance splits by LF only, there may be left over CR's that smell as if they lead to issues we're experiencing here. -
Christian Kuhn commented on patch set 3 12/12/24, 11:01
Reply
changed to a 'not resolved' note. -
Albrecht Köhnlein commented on patch set 3 12/16/24, 19:28
Reply
Hi Lolli, thanks for your time and feedback. > I would guess the true reason for all this fuzz with linebreaks in textarea fields is broken parsing on either js, or server side, or both In my opinion, this problem has nothing to do with JavaScript or server side processing. As you can see in my example https://codepen.io/koehnlein/pen/gONOWQW, it is a simple static HTML phenomenon. Line breaks in source code directly after the <textarea> tag is ignored in all browsers, I tested. While line breaks directly before </textarea> are kept. -
Benjamin Franzke commented on patch set 3 CR -1 12/17/24, 14:42
Reply
Yes @ak@koehnlein.eu is right, it is defined by the HTML spec that the first LF char is to be ignored: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody:~:text=A%20start%20tag%20whose%20tag%20name%20is%20%22textarea%22We do not write commit messages in first person but in imperative present tense: https://docs.typo3.org/permalink/t3contribute:commitmessage You can actually remove this paragraph and refer to the spec instead: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody:~:text=A%20start%20tag%20whose%20tag%20name%20is%20%22textarea%22table-wizard-element.ts:75Why is this condition removed? Is this actually related to this fix? Adding a trailing LF char does not change the value, except if a LF was the first char. Now, this became more likely but not impossible with this change, so why exactly is this removed? -
Christian Kuhn commented on patch set 3 12/17/24, 14:51
Reply
ah. this completes the picture and explains the current behavior. -
Albrecht Köhnlein updated the commit message in patch set 4
CR +1V +112/18/24, 19:25 -
core-ci voted on patch set 4 V +1 12/18/24, 19:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71410
-
Albrecht Köhnlein commented on patch set 4 12/18/24, 19:43
Reply
Thank you very much. I have also tried to find an official document, but have not succeeded. This helps a lot!table-wizard-element.ts:75ReplyI would say "yes". But I would also accept if you recommend to create a second issue and fix for it. There is one edge case where this is relevant: If you have a table with only one column and the table should start with empty rows. In this case, there are no field delimiters, because there is only one column. So table with the empty rows would look like this: ```html <textarea> second row</textarea> ``` After fixing the line breaks in the HTML codes, it looked consistent for me, to also cover this case. But as already written above, I also could undo it here and create a second issue for that. -
Benjamin Franzke uploaded patch set 5
V +112/19/24, 13:54 -
Benjamin Franzke commented on patch set 5 12/19/24, 13:54
table-wizard-element.ts:75ReplyHm, yes, we should move it into a different patch, because I feel like there is more off, when I look into `writeTableSyntaxToTextarea` I guess that we actually need a database migration to replace trailing newlines from the database, as they are added right now. Otherwise the fix would mean that a single-column table will be interpreted as having a trailing empty cell by the new parser code. ALso I'd rewrite `writeTableSyntaxToTextarea` to be more readable and avoid adding newlines first, just to remove them via regex. Alternative is: ``` private writeTableSyntaxToTextarea(): void { const textarea: HTMLTextAreaElement = document.querySelector(this.selectorData); textarea.value = this.table .map( row => row.map( word => ( // Build enclosed representation of column value this.enclosure + // Substitute newlines by `<br>` word.replace(/\r?\n/g, '<br>') + this.enclosure ) ).join(this.delimiter) ) .join('\n'); textarea.dispatchEvent(new CustomEvent('change', { bubbles: true })); } ``` but let's do that in a different patch -
Benjamin Franzke uploaded patch set 6
CR +1V +112/19/24, 13:59 -
core-ci voted on patch set 5 V -1 12/19/24, 14:02 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71454
-
core-ci voted on patch set 6 V +1 12/19/24, 14:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71456
-
Georg Ringer commented on patch set 6 12/20/24, 08:51
can't we move that new method to AbstractFormElement to avoid misusing GeneralUtility? -
Benjamin Franzke commented on patch set 6 12/20/24, 09:18
Reply
I don't care. It's annoying wherever we put it, but not having a utility method was too implicit, therefore I added it. Argument pro `GeneralUtlity`: It already contains methods for rendering HTML (`implodeAttributes`) – `AbstractFormElement` does not. -
Georg Ringer commented on patch set 6 CR +1 V +1 12/20/24, 18:58
as it is internal, we can move it someday anyway, so - yeah not really important -
Garvin Hicking commented on patch set 6 12/20/24, 22:42
What about other occurences of <textarea> and Extbase f:form.textara VH for example, is that unaffected? -
Albrecht Köhnlein uploaded patch set 7
CR +1V +112/21/24, 20:28 -
core-ci voted on patch set 7 V +1 12/21/24, 20:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71532
-
Albrecht Köhnlein commented on patch set 6 12/21/24, 20:36
Reply
Theoretically, all `<textarea>` that do not have a line break after the opening tag, are affected. The question is only, if there is a use case where it leads to an error. For example, if the value is processed via `trim()` before the output, it can be ignored. And there are cases in the code, where adding a line break after the opening tag would make the code much more ugly and even harde to read. For example in some HTML templates, where Benjamin's method cannot be applied. I would say, this changes now cover all critical occurences. Thanks for mentioning `<f:form.textarea>`. I fixed it there, too. On the other hand: Who defines cricital occurences? Just because I could not imagine problematic use cases for some of the textareas, does not mean, there never will be one. So we now have two ways to go: 1) Merge the patch as it is to improve some edge use cases. 2) Invest more effort to find all textareas and change them -
Garvin Hicking commented on patch set 7 12/21/24, 20:48
Reply
Very thankful for your evaluation. I do believe any further occurences should not block this patch and could act as follow-ups. I'm resolving this to not be a hold-up. (can't vote on it as I wasn't able yet to really understand the implications, so I'm happy if @bnf can 😊) -
Christian Kuhn uploaded patch set 8
V +101/06/25, 11:49 -
Christian Kuhn voted on patch set 8 CR +1 V +1 01/06/25, 11:49
-
core-ci voted on patch set 8 V +1 01/06/25, 11:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71981
-
Benjamin Franzke commented on patch set 8 CR -1 01/06/25, 12:21
Reply
Hm, I'm not really happy that we change frontend output with the fluid vh adaption. I know, each bugfix is possibly breaking for previous workarounds, but I feel like this is kinda uneeded. I'd adapt the fluid-vh in main-only, if at all and I'd output the LF only if there is actual content (as the GU `renderTextarea` method does) – for sake of unneeded bytes in an empty textarea (and better "style"). @gh@faktor-e.de Is it OK for you to remove this again? -
Garvin Hicking commented on patch set 8 01/06/25, 12:26
Reply
Please go ahead. I can't judge the implications, I'm good with whatever route this goes. -
Benjamin Franzke uploaded patch set 9
CR +1V +101/06/25, 12:29 -
Benjamin Franzke commented on patch set 9 01/06/25, 12:29
Reply
Done -
core-ci voted on patch set 9 V +1 01/06/25, 12:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/71984
-
Christian Kuhn voted on patch set 9 CR +1 V +1 01/06/25, 13:22
-
Riccardo De Contardi commented on patch set 9 V +1 01/06/25, 16:40
verified on latest main -
Benjamin Franzke voted on patch set 9 CR +2 V +2 01/07/25, 08:13
-
Benjamin Franzke merged patch set 10 01/07/25, 08:32
-
Mathias Brodala commented on patch set 10 01/07/25, 08:34
GeneralUtility.php:1032Here I thought that the long-term goal was to shrink down GU to eventually drop it ... -
Benjamin Franzke commented on patch set 10 01/07/25, 09:34
GeneralUtility.php:1032ReplyPlease see following comment for justification: https://review.typo3.org/c/Packages/TYPO3.CMS/+/87217/10#message-173d28839a697b31f8cfde7b26724daddf896011 -
Mathias Brodala commented on patch set 10 01/07/25, 09:46
GeneralUtility.php:1032ReplyThe justification reads to me "we already have a misplaced method, let's add another one". ;-) But I won't push any further since this new method is already marked "@internal", so it's safe to move it somewhere else at any time. -
Benjamin Franzke commented on patch set 10 01/07/25, 09:50
GeneralUtility.php:1032Replyexactly 👍