tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit eb9ba190413ecfa8ca24cf76636e62fb3eda4f14
parent 5878b829e245ff7c58a8a035e61ee1828841d1e3
Author: Emilio Cobos Álvarez <emilio@crisal.io>
Date:   Fri, 28 Nov 2025 22:58:52 +0000

Bug 2002971 - Remove trailing newlines when outputting a hard-wrapped line. r=smaug

Differential Revision: https://phabricator.services.mozilla.com/D274461

Diffstat:
Mdom/serializers/nsPlainTextSerializer.cpp | 4++++
Mtesting/web-platform/tests/html/semantics/forms/the-textarea-element/wrapping-transformation.window.js | 24++++++++++++++++++++++++
2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/dom/serializers/nsPlainTextSerializer.cpp b/dom/serializers/nsPlainTextSerializer.cpp @@ -1316,6 +1316,10 @@ void nsPlainTextSerializer::PerformWrapAndOutputCompleteLines( aLine.mContent.Truncate(goodSpace); // Append the line to the output. if (!aLine.mContent.IsEmpty()) { + // Trim _one_ potential trailing newline. + if (aLine.mContent.Last() == '\n') { + aLine.mContent.Truncate(goodSpace - 1); + } if (!aSettings.HasFlag(nsIDocumentEncoder::OutputPreformatted)) { aLine.mContent.Trim(" ", false, true, false); } diff --git a/testing/web-platform/tests/html/semantics/forms/the-textarea-element/wrapping-transformation.window.js b/testing/web-platform/tests/html/semantics/forms/the-textarea-element/wrapping-transformation.window.js @@ -56,3 +56,27 @@ test((t) => { "The value must be wrapped.", ); }, "Textarea wrapping transformation: Wrapping happens with LF newlines."); + +function assert_roundtrips(text) { + test((t) => { + const form = document.createElement("form"); + const textarea = document.createElement("textarea"); + textarea.name = "wrapTest"; + textarea.cols = 10; + textarea.wrap = "hard"; + form.appendChild(textarea); + document.body.appendChild(form); + t.add_cleanup(() => { + document.body.removeChild(form); + }); + textarea.value = text; + const formDataValue = new FormData(form).get("wrapTest"); + textarea.value = formDataValue; + const newFormDataValue = new FormData(form).get("wrapTest"); + assert_equals(formDataValue, newFormDataValue, "Value should round-trip"); + }, "Textarea wrapping transformation: wrapping round-trips: " + text); +} + +assert_roundtrips("Some text that is too long for the specified character width."); +assert_roundtrips("Some text that is too long for the\n\n\nspecified character width."); +assert_roundtrips("exact len");