Bug 160563 - Pasting very long string when editing in the formula input inserts newline(s)
Summary: Pasting very long string when editing in the formula input inserts newline(s)
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.6.5.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-06 08:36 UTC by Vlad-Mihai Sima
Modified: 2024-04-06 21:32 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Very long string example (16.00 KB, text/plain)
2024-04-06 08:37 UTC, Vlad-Mihai Sima
Details
Example of bad behavior (11.54 KB, application/vnd.oasis.opendocument.spreadsheet)
2024-04-06 08:37 UTC, Vlad-Mihai Sima
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Vlad-Mihai Sima 2024-04-06 08:36:48 UTC
Description:
Strings that are longer than around 17k characters will have a new line automatically inserted when pasted when editing in the formula input (with Ctr-Shift-V - unformulated text). This happens each ~16k characters (if you paste a string of ~40k you will get two new lines).

This is a problem if you paste - for example - a very long JSON file.

Steps to Reproduce:
1. Generate a string of more than 17k (actual limit is a bit below 16385 but did not compute exactly) (example in extra_newline.txt, generated with "head -c 16385 < /dev/zero | tr '\0' 'a' > extra_newline.txt")
2. Click on empty cell, click on the formula input (or press F2), press Ctrl-Shift-V, select "Unformatted text"). Press Enter or click somewhere else. (result in extra_newline.ods)
3. Copy value in cell and paste in a text editor (or check content.xml in the ods)



Actual Results:
The string had a new line (and a character transformed to caps).

Expected Results:
The string is the same as the pasted string.


Reproducible: Always


User Profile Reset: No

Additional Info:
Keep the string as it is.

Note: if you paste without going to the formula input (so, just click on cell and Ctrl-Shift-V) the cell will be displayed with the extra newline, but when copied back will be correct. If I check the actual file saved on disk it will contain the correct value (without the newline).

This suggests that there is somewhere in the code a transformation that happens for both display (probably not that important these cells are not meant to be read) but also, more importantly  while pasting when editing - which then is used as the correct value.

But if there is no reason to such transformation (adding the newline), probably it should be removed.
Comment 1 Vlad-Mihai Sima 2024-04-06 08:37:13 UTC
Created attachment 193540 [details]
Very long string example
Comment 2 Vlad-Mihai Sima 2024-04-06 08:37:30 UTC
Created attachment 193541 [details]
Example of bad behavior
Comment 3 Mike Kaganski 2024-04-06 13:02:08 UTC
Code pointer: ImpEditEngine::ImpInsertText ( https://opengrok.libreoffice.org/xref/core/editeng/source/editeng/impedit2.cxx?r=f61ea135#2731 ).
Comment 4 Vlad-Mihai Sima 2024-04-06 21:32:03 UTC
For clarity, not sure if this should/could be fixed or just the documentation improved or warning added on paste when issues is hit. When trying to figure out if I am doing something wrong I stumbled upon https://wiki.documentfoundation.org/Faq/Calc/022 which does not describe sufficiently the maximum size related issues. Ideally someone understanding the code could update the wiki describing any limitations in a clear language (my current understanding would be "no line can be larger than ~16k and it will be forcefully split if larger").

The most frustrating was that it was really not obvious what was happening (you can for example paste a JSON larger than 16k if it is formatted with new lines and if you do not have any string larger than 16k, because then Calc will just split on the existing newlines).