Problems with linebreaks in textarea (\r\n in instead of \n)

Since last week I get reports of my users, that saving contents in a textarea of different forms causes problems.

My Zope app does not use a form framework, but just accesses the REQUEST object to get the values of a form submission.

One example:
The users can set their signature themselves.

They go to the signature edit view, where the current signature is rendered into a text area.

When they hit save (with or without applied changes) the content is now saved with \r\n as line breaks, which breaks some following processes.

Previously it was just a \n.

This is true for different browsers and both on Windows and on Linux.

I tried a revision of my app back from June - and still the same problems.

Currently, I am completely puzzled about the origins of the problem.

Any hint for me? Is this a browser thing? OS? Zope? ....

Thank you.

P.S.: In the meanwhile I will go through my and Zope's changelog in order to find a hint.

jugmac00 via Plone Community wrote at 2020-11-24 14:36 +0000:

Since last week I get reports of my users, that saving contents in a textarea of different forms causes problems.

Which Zope and Python versions?

I am on Python 3.7.4 and Zope 4.5.1

I performed following updates:

  • 4.5.1 on 2020-09-20
  • 4.5 on 2020-07-28
  • 4.4 on 2020-04-21
  • 4.2.1 on 2020-02-13

Switch from Python 2 to 3 on 2020-07-25

Multiline entry fields (text are) are pretty rare in my app, and mostly filled with a single line anyway, so it is quite possible that the problem was hidden for a long time.

I will perform a git bisect to deploy previous states. As this is a bit quite some work due to data migration, I'd be super happy if I get a hint what could be possible going on.

I went back to my first commit after the Python 3 migration (Zope 4.4) and the problems are still present.

Ok, I found a method to narrow the problem, or at least since when it came to exist.

My app also provides a CMS application, with almost daily changes - via a form with a text area.

So I just have to go through the CMS entries, ordered by last modified. With a binary search this should be done quickly (tomorrow).

As the CMS continues to work, it seems only some (lesser used) parts of my app have problems with line breaks of the form \r\n.

The first entry with \r\n dates back to 2020-01-27, and this is the first working day after I migrated my app from Zope 2 to Zope 4.

I guess there were too many changes to track down the reason.

I need to make sure that those areas of my app, which have problems with the "new" line endings, can handle them properly.

jugmac00 via Plone Community wrote at 2020-11-24 14:36 +0000:

...
Any hint for me? Is this a browser thing? OS? Zope? ....

It is the browser ("firefox 83" in my case) which transform
the \n into `\r\n'.

How I found out?
I always have a show_request object which allows me to get
the request details.
For the verification, I defined a DTML Method textarea:

<html>
  <head>
    <title><dtml-var title_or_id></title>
    <meta charset="utf-8" />
  </head>
  <body>
  <form action="show_request" method="POST">
    <textarea name="v"><dtml-var v></textarea>
    <input type="submit" />
  </form>
  </body>
</html>

I used the "firefox" network analysis to see what happens
for the request "...textarea?v=a%0Ab"
and when I submit the form. This showed that "firefox" posted
"a\r\nb". I verify with wget that Zope has delivered a\nb.

Thanks @dieter!

Looks like there is an HTML specification for that, and when I read it correctly, a line break in a text area has to be \r\n.

As line breaks were stored as \n until I switched from Zope 2 to Zope 4, there had to be some conversion going on in Zope 2, which was removed back then.