From b176937c9e1edffe9dfbe6b56676004cf412bd09 Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Sat, 1 Feb 2020 10:56:41 +0100 Subject: [PATCH 1/4] Fix the crash on drag&drop/import of tiger.svgz. Fix the crash on drag&drop or import of tiger.svgz (and likely other *.svgz) into an empty inkscape doc. With an automated test. The test is a regression "unit"ish test. See: * https://gitlab.com/inkscape/inkscape/issues/906 . Happens also on "File -> Import"ing an .svgz file. Add a new SVG_COMMON_INPUT_PARAMS macro in svg.h. Add svg.h to POTFILES.*.in for the translations pipeline Add MIT License to PERMITTED_LICENSES . --- buildtools/check_license_headers.py | 1 + po/POTFILES.src.in | 1 + src/extension/internal/svg.cpp | 14 +----- src/extension/internal/svg.h | 15 +++++++ src/extension/internal/svgz.cpp | 1 + testfiles/CMakeLists.txt | 1 + testfiles/src/drag-and-drop-svgz.cpp | 66 ++++++++++++++++++++++++++++ 7 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 testfiles/src/drag-and-drop-svgz.cpp diff --git a/buildtools/check_license_headers.py b/buildtools/check_license_headers.py index 5291216d61..9741f0333a 100755 --- a/buildtools/check_license_headers.py +++ b/buildtools/check_license_headers.py @@ -74,6 +74,7 @@ PERMITTED_LICENSES = [ "GPL-3.0-or-later", "LGPL-2.1-or-later", "LGPL-3.0-or-later", + "MIT", ] diff --git a/po/POTFILES.src.in b/po/POTFILES.src.in index 434ebd1ae9..113cc10a94 100644 --- a/po/POTFILES.src.in +++ b/po/POTFILES.src.in @@ -91,6 +91,7 @@ ../src/extension/internal/pdfinput/pdf-input.cpp ../src/extension/internal/pov-out.cpp ../src/extension/internal/svg.cpp +../src/extension/internal/svg.h ../src/extension/internal/svgz.cpp ../src/extension/internal/vsd-input.cpp ../src/extension/internal/wmf-inout.cpp diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 0a69887928..caa090bb88 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -727,19 +727,7 @@ Svg::init() "\n" "" N_("SVG Input") "\n" "" SP_MODULE_KEY_INPUT_SVG "\n" - "\n" - "\n" - "\n" - "\n" - "\n" - "96.00\n" - "\n" - "\n" - "\n" - "\n" - "\n" - - "false\n" + SVG_COMMON_INPUT_PARAMS "\n" ".svg\n" "image/svg+xml\n" diff --git a/src/extension/internal/svg.h b/src/extension/internal/svg.h index 1eb4f51e8d..a7adba43ba 100644 --- a/src/extension/internal/svg.h +++ b/src/extension/internal/svg.h @@ -18,6 +18,21 @@ #include "../implementation/implementation.h" +#define SVG_COMMON_INPUT_PARAMS \ + "\n" \ + "\n" \ + "\n" \ + "\n" \ + "\n" \ + "96.00\n" \ + "\n" \ + "\n" \ + "\n" \ + "\n" \ + "\n" \ + "false\n" + + namespace Inkscape { namespace Extension { namespace Internal { diff --git a/src/extension/internal/svgz.cpp b/src/extension/internal/svgz.cpp index 18b6e5b026..ea00f943b1 100644 --- a/src/extension/internal/svgz.cpp +++ b/src/extension/internal/svgz.cpp @@ -44,6 +44,7 @@ Svgz::init() "" N_("SVGZ Input") "\n" "" SP_MODULE_KEY_INPUT_SVGZ "\n" "" SP_MODULE_KEY_INPUT_SVG "\n" + SVG_COMMON_INPUT_PARAMS "\n" ".svgz\n" "image/svg+xml-compressed\n" diff --git a/testfiles/CMakeLists.txt b/testfiles/CMakeLists.txt index 646505e083..8a6825709e 100644 --- a/testfiles/CMakeLists.txt +++ b/testfiles/CMakeLists.txt @@ -15,6 +15,7 @@ include_directories("${CMAKE_SOURCE_DIR}/src/3rdparty/adaptagrams") set(TEST_SOURCES uri-test + drag-and-drop-svgz extract-uri-test attributes-test color-profile-test diff --git a/testfiles/src/drag-and-drop-svgz.cpp b/testfiles/src/drag-and-drop-svgz.cpp new file mode 100644 index 0000000000..ab7ae5a607 --- /dev/null +++ b/testfiles/src/drag-and-drop-svgz.cpp @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: MIT +/** + * @file + * Test that svgz (= compressed SVG) import/drag-and-drop + * is working: https://gitlab.com/inkscape/inkscape/issues/906 . + * + */ +/* + * Authors: + * Shlomi Fish + * + * Copyright (C) 2020 Authors + */ + +#include "doc-per-case-test.h" +#include + +#include "extension/db.h" +#include "extension/find_extension_by_mime.h" +#include "extension/internal/svgz.h" +#include "path-prefix.h" +#include "preferences.h" + +#include "gtest/gtest.h" + +#ifdef _WIN32 +#include // provides SetDllDirectoryW +#endif + + +class SvgzImportTest : public DocPerCaseTest { + public: + SvgzImportTest() {} + void TestBody() + { + ASSERT_TRUE(_doc != nullptr); + ASSERT_TRUE(_doc->getRoot() != nullptr); + Inkscape::Preferences *prefs = Inkscape::Preferences::get(); + prefs->setBool("/dialogs/import/ask_svg", true); + prefs->setBool("/options/onimport", true); + auto ext = Inkscape::Extension::find_by_mime("image/svg+xml-compressed"); + ext->set_gui(true); + auto fn = Glib::build_filename(INKSCAPE_EXAMPLESDIR, "tiger.svgz"); + auto imod = dynamic_cast(ext); + auto svg_mod = (new Inkscape::Extension::Internal::Svg); + ASSERT_TRUE(svg_mod->open(imod, fn.c_str()) != nullptr); + } + ~SvgzImportTest() override {} +}; + +TEST_F(SvgzImportTest, Eq) +{ + SvgzImportTest foo; + foo.TestBody(); +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- GitLab From 7cc1c5e0bffb5e7f6b2b77a08d44139d9abbcaa0 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 13 Feb 2020 07:25:13 +0200 Subject: [PATCH 2/4] Dual license an original file. See the discussion at https://gitlab.com/inkscape/inkscape/-/merge_requests/1383 . Note that it may not be needed due to https://www.gnu.org/licenses/license-list.html#Expat and https://en.wikipedia.org/wiki/JQuery#History ( IANAL / TINLA / etc. ) --- buildtools/check_license_headers.py | 1 - testfiles/src/drag-and-drop-svgz.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/buildtools/check_license_headers.py b/buildtools/check_license_headers.py index 9741f0333a..5291216d61 100755 --- a/buildtools/check_license_headers.py +++ b/buildtools/check_license_headers.py @@ -74,7 +74,6 @@ PERMITTED_LICENSES = [ "GPL-3.0-or-later", "LGPL-2.1-or-later", "LGPL-3.0-or-later", - "MIT", ] diff --git a/testfiles/src/drag-and-drop-svgz.cpp b/testfiles/src/drag-and-drop-svgz.cpp index ab7ae5a607..73c906f4fd 100644 --- a/testfiles/src/drag-and-drop-svgz.cpp +++ b/testfiles/src/drag-and-drop-svgz.cpp @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: MIT +// SPDX-License-Identifier: GPL-2.0+ OR MIT /** * @file * Test that svgz (= compressed SVG) import/drag-and-drop -- GitLab From 70b0e418a63a03ec0759b5e5802b3e0572d9c799 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 13 Feb 2020 07:34:28 +0200 Subject: [PATCH 3/4] remove unneeded include --- testfiles/src/drag-and-drop-svgz.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/testfiles/src/drag-and-drop-svgz.cpp b/testfiles/src/drag-and-drop-svgz.cpp index 73c906f4fd..de62634628 100644 --- a/testfiles/src/drag-and-drop-svgz.cpp +++ b/testfiles/src/drag-and-drop-svgz.cpp @@ -23,10 +23,6 @@ #include "gtest/gtest.h" -#ifdef _WIN32 -#include // provides SetDllDirectoryW -#endif - class SvgzImportTest : public DocPerCaseTest { public: -- GitLab From 6d4489ae277c61ec34684d71cd7794870c65e3a7 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Thu, 13 Feb 2020 08:07:22 +0200 Subject: [PATCH 4/4] fix SPDX license test --- testfiles/src/drag-and-drop-svgz.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testfiles/src/drag-and-drop-svgz.cpp b/testfiles/src/drag-and-drop-svgz.cpp index de62634628..5ea7c0b0aa 100644 --- a/testfiles/src/drag-and-drop-svgz.cpp +++ b/testfiles/src/drag-and-drop-svgz.cpp @@ -1,4 +1,4 @@ -// SPDX-License-Identifier: GPL-2.0+ OR MIT +// SPDX-License-Identifier: GPL-2.0-or-later OR MIT /** * @file * Test that svgz (= compressed SVG) import/drag-and-drop -- GitLab