[frameworks/kcodecs] /: [KEncodingProber] Fix broken UTF16 filtering for MBCS
Stefan Brüns <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit f3c71ebfc6694189954fe77b27c44691f46fabe1 by Stefan Brüns.
Committed on 31/07/2026 at 07:01.
Pushed by bruns into branch 'master'.
[KEncodingProber] Fix broken UTF16 filtering for MBCS
M +1 -1 autotests/kencodingprobertest.cpp
M +16 -5 src/probers/nsMBCSGroupProber.cpp
https://invent.kde.org/frameworks/kcodecs/-/commit/f3c71ebfc6694189954fe77b27c44691f46fabe1
diff --git a/autotests/kencodingprobertest.cpp b/autotests/kencodingprobertest.cpp
index 5bbc008..2919bf2 100644
--- a/autotests/kencodingprobertest.cpp
+++ b/autotests/kencodingprobertest.cpp
@@ -123,7 +123,6 @@ void KEncodingProberTest::testProbe()
QEXPECT_FAIL("Konnichiwa UTF-16LE", "Too low UTF-16LE confidence, too high Win-1252", Abort);
QEXPECT_FAIL("Konnichiwa UTF-16BE", "Too low UTF-16BE confidence, too high Win-1252", Abort);
QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE Universal", "Too low UTF-16LE confidence, too high Win-1252", Abort);
- QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE", "MBCS filter broken", Abort);
QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE Universal", "Too low UTF-16BE confidence, too high Win-1252", Abort);
QCOMPARE(ep.encoding().toLower(), encoding);
@@ -133,6 +132,7 @@ void KEncodingProberTest::testProbe()
QEXPECT_FAIL("UTF-16BE Unicode definite 2", "UTF-16 zero confidence", Abort);
QEXPECT_FAIL("UTF-16LE Unicode definite 2", "UTF-16 zero confidence", Abort);
QEXPECT_FAIL("utf-8 Japanese", "Too low UTF-8 confidence", Abort);
+ QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16LE", "UTF-16 zero confidence", Abort);
QEXPECT_FAIL("EnjoyPlasma Japanese UTF-16BE", "UTF-16 zero confidence", Abort);
QCOMPARE_GE(ep.confidence(), 0.2);
}
diff --git a/src/probers/nsMBCSGroupProber.cpp b/src/probers/nsMBCSGroupProber.cpp
index 8115d49..f2a82b6 100644
--- a/src/probers/nsMBCSGroupProber.cpp
+++ b/src/probers/nsMBCSGroupProber.cpp
@@ -121,7 +121,18 @@ nsProbingState nsMBCSGroupProber::HandleData(const char *aBuf, unsigned int aLen
}
}
- for (unsigned int i = 0; i < NUM_OF_PROBERS; ++i) {
+ // The UTF16 probers need unmangled data
+ for (unsigned int i = NUM_OF_PROBERS - 2; i < NUM_OF_PROBERS; ++i) {
+ if (!mIsActive[i]) {
+ continue;
+ }
+ if (const auto st = mProbers[i]->HandleData(aBuf, aLen); st == eNotMe) {
+ mIsActive[i] = false;
+ mActiveNum--;
+ }
+ }
+
+ for (unsigned int i = 0; i < NUM_OF_PROBERS - 2; ++i) {
if (!mIsActive[i]) {
continue;
}
@@ -133,13 +144,13 @@ nsProbingState nsMBCSGroupProber::HandleData(const char *aBuf, unsigned int aLen
} else if (st == eNotMe) {
mIsActive[i] = false;
mActiveNum--;
- if (mActiveNum == 0) {
- mState = eNotMe;
- break;
- }
}
}
+ if (mActiveNum == 0) {
+ mState = eNotMe;
+ }
+
free(highbyteBuf);
return mState;