Bug 466814 - dolphin rename file selects part of the extension when name contains composed glyphs (diacritics, emojis)
Summary: dolphin rename file selects part of the extension when name contains composed...
Status: REPORTED
Alias: None
Product: dolphin
Classification: Applications
Component: view-engine: general (show other bugs)
Version: 22.08.2
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Dolphin Bug Assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-04 07:52 UTC by kdebugs
Modified: 2023-05-20 09:47 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kdebugs 2023-03-04 07:52:09 UTC
SUMMARY
Dolphin improperly counts characters when attempting to select everything but the ".ext".

STEPS TO REPRODUCE
1. Make a file named "épée.txt"
[NB: each é is composed of U+0065 (lowercase letter e) plus U+0301 (combining acute accent).  The filename does NOT use the precomposed character U+00E9.]
2. Select the file and hit F2 (or right-click and select Rename...)

OBSERVED RESULT
Dolphin selects "épée.t"

EXPECTED RESULT
Dolphin should select "épée"

SOFTWARE/OS VERSIONS
Kubuntu 22.10
KDE Plasma Version: 5.25.5
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6

ADDITIONAL INFORMATION

Second example, but with emojis:
"zz❤️❤️.txt" (NB: each of the two hearts is composed of U+2764 followed by U+FE0F)

Without looking at the code, I'm guessing someone did something naive like QTextCursor.movePosition() by a certain number of characters.  The programmer should understanding that Qt counts cursor positions in QChar (always 16-bit, so sometimes partial characters), however movePosition jumps over composed/joined characters as a unit, so neither setPosition() nor movePosition() are suitable for placing the cursor at a given character offset.  You must first encode the string you want to select as utf-16 and divide the resulting length in bytes by 2.  This number is what you use to determine a QChar offset which can be passed to setPosition.

[If done right, that should put you in front of the period (.) which is safe enough.  In other contexts, you would want to also make sure that your moving by x number of characters doesn't land you in the middle of a composed glyph.  You can do that by using movePosition to advance 1 character and then again to go back 1 character.  If you weren't in the middle of a glyph, this doesn't move you, but if you were, it safely puts you in front of whatever you were in.]
Comment 1 kde 2023-05-20 09:47:44 UTC
I also just experienced this bug. Dolphin version 23.04.0.

The amount of open bugs around dolphin just shocked me!