https://bugs.kde.org/show_bug.cgi?id=528700
Bug ID: 528700
Summary: Non-ASCII tag names are double-encoded when items are
stored with name-only tags (GID scope uses
QString::fromLatin1)
Classification: Frameworks and Libraries
Product: Akonadi
Version First 6.8.2
Reported In:
Platform: openSUSE
OS: Linux
Status: REPORTED
Severity: normal
Priority: NOR
Component: libakonadi
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
Target Milestone: ---
Description:
When an item is stored with a tag that has only a GID (for example
Tag(QStringLiteral("Škola")), without an id), libakonadi sends the GID to the
server decoded as Latin-1 instead of UTF-8. The server resolves the tag by
that string, does not find the existing tag, and creates a new tag with a
mojibake name ("Å kola") that gets attached to the item.
The Google Groupware resource runs into this on every calendar sync:
CalendarHandler turns each event category into item.setTag(Tag(category)),
so every event with a non-ASCII category that arrives by sync gets the
broken tag. KOrganizer then shows those events with the category "Å kola"
(uncolored), instead of or next to the correct "Škola".
Cause:
src/core/protocolhelper_p.h:264, ProtocolHelper::entitySetToRemoteIdentifier():
return QString::fromLatin1(ridFunc(obj));
For Tag, gid() is a QByteArray holding UTF-8 (Tag::Tag(const QString &name)
sets gid = name.toUtf8()), while Scope::Gid carries a QStringList. The server
treats tag GIDs as UTF-8 elsewhere:
- TagCreateHandler: QString::fromUtf8(cmd.gid())
- HandlerHelper::fetchTagsResponse: response.setGid(tag.gid().toUtf8())
- HandlerHelper::resolveTagsByGID: looks up / inserts the received QString
as is
So "Škola" (UTF-8 C5 A0 6B 6F 6C 61) reaches the server as U+00C5 U+00A0 "kola"
and is stored as C3 85 C2 A0 6B 6F 6C 61.
Using QString::fromUtf8() in that branch should fix this. Only Tag reaches
that branch (Item::gid(), Item::remoteId() and Collection::remoteId() are
already QString), so the change affects exactly tag GIDs and tag remote IDs.
Tag remote IDs have the same mismatch: TagCreateHandler and TagModifyHandler
store them with QString::fromUtf8(cmd.remoteId()), but
HandlerHelper::resolveTagsByRID() compares against the Latin-1-decoded string
from the scope. If nothing matches, it creates a new tag with GID = that
string, which is mojibake again.
The fix does not repair existing data: tags already created with mojibake
names, and their item links, stay until they are cleaned up.
Possibly related: src/core/tagsync.cpp:144 and :170 also use
QString::fromLatin1(tag.remoteId()) as hash keys; I have not traced that.
Steps to reproduce:
1. Add a Google Groupware resource with a calendar.
2. In KOrganizer, create an event in that calendar and give it a new category
containing a non-ASCII character, e.g. "Škola". (This tag is created through
TagCreateJob and is stored correctly.)
3. Change the event outside this Akonadi instance, e.g. edit its title in the
Google Calendar web UI, or on another computer syncing the same calendar.
4. Let the resource sync.
Observed: the event gets an additional tag "Å kola", and a new TagTable row
with gid C3 85 C2 A0 6B 6F 6C 61 appears. Events with category "Škola" that are
new to this machine get only the "Å kola" tag. The event payload itself stays
correct (CATEGORIES:Škola).
Expected: the event keeps / gets the existing "Škola" tag.
(These steps follow the code path above and match what I see in my
database; I did not do a separate clean-room test.)
Evidence from my Akonadi database:
TagTable:
id 31 gid "Škola" hex C5A06B6F6C61
id 184 gid "Å kola" hex C385C2A06B6F6C61 (no TagAttribute, so no
color)
- 21 events in the Google calendar carry tag 184. All of them were last
written by the Google resource during a sync, and all their payloads say
CATEGORIES:Škola. 13 of them also still have tag 31.
- Two of them were created by a sync and never modified afterwards (rev 0):
payload says "Škola", the only tag is 184. Payload and tag come from the
same fetched event, so the corruption happens inside Akonadi, not in the
data on Google.
- Categories with ASCII names ("Tanec", "Rodina", ...) match their tags on
every item. Only categories with diacritics ("Škola", "Práce", "Hrádek")
are inconsistent.
Follow-on effects in the Google resource (kdepim-runtime):
- CalendarHandler::copyTagsToCategories() (calendarhandler.cpp:207) replaces
the event's categories with the item's tag names before uploading. Once an
event has the broken tag, editing it locally uploads "Škola,Å kola" to
Google. Other machines then receive "Å kola" and double-encode it again.
- Sync merges only send addedTags, so the wrong tag is never removed
automatically.
Software:
openSUSE Leap 16.0
Akonadi / KDE PIM 26.08.3 (akonadi, kdepim-runtime, libkgapi)
KDE Frameworks 6.31.0
Qt 6.12.0
Akonadi database: MariaDB 11.8.8 (QMYSQL)
--
You are receiving this mail because:
You are watching all bug changes.