[poppler] qt5/src qt5/tests qt6/src qt6/tests

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 14 07:51:35 UTC 2021


 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 <albert.astals.cid at kdab.com>
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 <adam.reichold at t-online.de>
  * Copyright (C) 2019, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2019 João Netto <joaonetto901 at gmail.com>
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>
  * Inspired on code by
  * Copyright (C) 2004 by Albert Astals Cid <tsdgeos at terra.es>
  * Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
@@ -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 <pino at kde.org>
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>
  *
  * 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 <adam.reichold at t-online.de>
  * Copyright (C) 2019, 2020 Oliver Sander <oliver.sander at tu-dresden.de>
  * Copyright (C) 2019 João Netto <joaonetto901 at gmail.com>
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>
  * Inspired on code by
  * Copyright (C) 2004 by Albert Astals Cid <tsdgeos at terra.es>
  * Copyright (C) 2004 by Enrico Ros <eros.kde at email.it>
@@ -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 <pino at kde.org>
+ * Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info at kdab.com>
  *
  * 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;
 }


More information about the poppler mailing list