[frameworks/kconfig] src/core: Use Qt for ASCII && alphanumeric detection

Andreas Hartmetz <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 53e3b5802cdf8b28cc5285f2dbd322963f77ccbd by Andreas Hartmetz.
Committed on 22/07/2026 at 19:50.
Pushed by ahartmetz into branch 'master'.

Use Qt for ASCII && alphanumeric detection

This fixes a recent widely reported crash due to some distro
packaging issues in iconv(?) and exposes this code only to Qt bugs
instead of Qt *and* libc / stdlibc localization bugs.
Qt has a very good track record in that particular area.

M  +8    -6    src/core/dbussanitizer_p.h

https://invent.kde.org/frameworks/kconfig/-/commit/53e3b5802cdf8b28cc5285f2dbd322963f77ccbd

diff --git a/src/core/dbussanitizer_p.h b/src/core/dbussanitizer_p.h
index a90d7440..af334199 100644
--- a/src/core/dbussanitizer_p.h
+++ b/src/core/dbussanitizer_p.h
@@ -3,16 +3,18 @@
 
 #pragma once
 
-#include <cctype>
-#include <locale>
-
+#include <QChar>
+#include <QLatin1Char>
 #include <QString>
 
 inline QString kconfigDBusSanitizePath(QString path)
 {
-    for (auto &character : path) {
-        if ((std::isalnum(character.toLatin1(), std::locale::classic()) == 0) && character != QLatin1Char('_') && character != QLatin1Char('/')) {
-            character = QLatin1Char('_');
+    for (auto &c : path) {
+        // Quote DBus spec: 'Each element must only contain the ASCII characters "[A-Z][a-z][0-9]_"'
+        // (and '/' is the element separator)
+        const bool isAscii = c.unicode() < 128; // note: char16_t is always unsigned
+        if (!isAscii || (!c.isLetterOrNumber() && c != QLatin1Char('_') && c != QLatin1Char('/'))) {
+            c = QLatin1Char('_');
         }
     }
     // KConfig notifying or watching on / makes no sense
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.