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
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
* Copyright (C) 2019, 2020 Oliver Sander
* Copyright (C) 2019 João Netto
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company,
* Inspired on code by
* Copyright (C) 2004 by Albert Astals Cid
* Copyright (C) 2004 by Enrico Ros
@@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string )
GooString *QStringToUnicodeGooString(const QString )
{
+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
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company,
*
* 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
* Copyright (C) 2019, 2020 Oliver Sander
* Copyright (C) 2019 João Netto
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company,
* Inspired on code by
* Copyright (C) 2004 by Albert Astals Cid
* Copyright (C) 2004 by Enrico Ros
@@ -115,6 +116,9 @@ QString UnicodeParsedString(const std::string )
GooString *QStringToUnicodeGooString(const QString )
{
+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
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company,
*
* 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
poppler@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/poppler