qt5/src/poppler-private.cc | 4 ++++ qt5/tests/check_strings.cpp | 12 +++++++++--- qt6/src/poppler-private.cc | 4 ++++ qt6/tests/check_strings.cpp | 12 +++++++++--- 4 files changed, 26 insertions(+), 6 deletions(-)
New commits: commit b770a55a47278f4104fc410034577cc4ea0434a6 Author: Albert Astals Cid <[email protected]> Date: Tue Apr 13 17:59:34 2021 +0200 qt: QStringToUnicodeGooString don't produce a "fake empty" string if the input string is empty, just return an empty GooString, not a GooString with only the unicode marker diff --git a/qt5/src/poppler-private.cc b/qt5/src/poppler-private.cc index 5b30f19c..695b9b8c 100644 --- a/qt5/src/poppler-private.cc +++ b/qt5/src/poppler-private.cc @@ -9,6 +9,7 @@ * Copyright (C) 2018-2020 Adam Reichold <[email protected]> * Copyright (C) 2019, 2020 Oliver Sander <[email protected]> * Copyright (C) 2019 João Netto <[email protected]> + * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]> * Inspired on code by * Copyright (C) 2004 by Albert Astals Cid <[email protected]> * Copyright (C) 2004 by Enrico Ros <[email protected]> @@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string &s1) GooString *QStringToUnicodeGooString(const QString &s) { + if (s.isEmpty()) { + return new GooString(); + } int len = s.length() * 2 + 2; char *cstring = (char *)gmallocn(len, sizeof(char)); cstring[0] = (char)0xfe; diff --git a/qt5/tests/check_strings.cpp b/qt5/tests/check_strings.cpp index 4c996c4f..14d22740 100644 --- a/qt5/tests/check_strings.cpp +++ b/qt5/tests/check_strings.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010, 2011, Pino Toscano <[email protected]> + * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -189,9 +190,14 @@ void TestStrings::check_QStringToUnicodeGooString() QFETCH(QByteArray, result); GooString *goo = Poppler::QStringToUnicodeGooString(string); - QVERIFY(goo->hasUnicodeMarker()); - QCOMPARE(goo->getLength(), string.length() * 2 + 2); - QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, goo->getLength() - 2)); + if (string.isEmpty()) { + QVERIFY(goo->toStr().empty()); + QCOMPARE(goo->getLength(), 0); + } else { + QVERIFY(goo->hasUnicodeMarker()); + QCOMPARE(goo->getLength(), string.length() * 2 + 2); + QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, goo->getLength() - 2)); + } delete goo; } diff --git a/qt6/src/poppler-private.cc b/qt6/src/poppler-private.cc index c60876da..a2971adc 100644 --- a/qt6/src/poppler-private.cc +++ b/qt6/src/poppler-private.cc @@ -9,6 +9,7 @@ * Copyright (C) 2018-2020 Adam Reichold <[email protected]> * Copyright (C) 2019, 2020 Oliver Sander <[email protected]> * Copyright (C) 2019 João Netto <[email protected]> + * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]> * Inspired on code by * Copyright (C) 2004 by Albert Astals Cid <[email protected]> * Copyright (C) 2004 by Enrico Ros <[email protected]> @@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string &s1) GooString *QStringToUnicodeGooString(const QString &s) { + if (s.isEmpty()) { + return new GooString(); + } int len = s.length() * 2 + 2; char *cstring = (char *)gmallocn(len, sizeof(char)); cstring[0] = (char)0xfe; diff --git a/qt6/tests/check_strings.cpp b/qt6/tests/check_strings.cpp index c887105c..fdd2f703 100644 --- a/qt6/tests/check_strings.cpp +++ b/qt6/tests/check_strings.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2010, 2011, Pino Toscano <[email protected]> + * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <[email protected]> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -189,9 +190,14 @@ void TestStrings::check_QStringToUnicodeGooString() QFETCH(QByteArray, result); GooString *goo = Poppler::QStringToUnicodeGooString(string); - QVERIFY(goo->hasUnicodeMarker()); - QCOMPARE(goo->getLength(), string.length() * 2 + 2); - QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, goo->getLength() - 2)); + if (string.isEmpty()) { + QVERIFY(goo->toStr().empty()); + QCOMPARE(goo->getLength(), 0); + } else { + QVERIFY(goo->hasUnicodeMarker()); + QCOMPARE(goo->getLength(), string.length() * 2 + 2); + QCOMPARE(result, QByteArray::fromRawData(goo->c_str() + 2, goo->getLength() - 2)); + } delete goo; } _______________________________________________ poppler mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/poppler
