[librsvg: 4/5] rsvg-convert: Reject invalid resolutions (negative or zero)




commit 5d3d47383b592096b66f634e53d13dd8faf57118
Author: Sven Neumann <sven svenfoo org>
Date:   Thu Nov 5 17:37:44 2020 +0100

    rsvg-convert: Reject invalid resolutions (negative or zero)
    
    The tool used to silently use the default of 90 dpi if passed invalid
    resolutions. Change it so it rejects negative and zero values. Adjust
    the tests accordingly.

 rsvg-convert.c                    | 13 +++++--------
 tests/src/cmdline/rsvg_convert.rs | 12 ++++++------
 2 files changed, 11 insertions(+), 14 deletions(-)
---
diff --git a/rsvg-convert.c b/rsvg-convert.c
index cb17345d..922713e9 100644
--- a/rsvg-convert.c
+++ b/rsvg-convert.c
@@ -211,8 +211,8 @@ main (int argc, char **argv)
     double x_zoom = 1.0;
     double y_zoom = 1.0;
     double zoom = 1.0;
-    double dpi_x = -1.0;
-    double dpi_y = -1.0;
+    double dpi_x = 90.0;
+    double dpi_y = 90.0;
     int width = -1;
     int height = -1;
     int bVersion = 0;
@@ -350,12 +350,9 @@ main (int argc, char **argv)
         exit (1);
     }
 
-    if (dpi_x <= 0.0) {
-        dpi_x = 90.0;
-    }
-
-    if (dpi_y <= 0.0) {
-        dpi_y = 90.0;
+    if (dpi_x <= 0.0 || dpi_y <= 0.0) {
+        g_printerr (_("Invalid resolution\n"));
+        exit (1);
     }
 
     if (format != NULL &&
diff --git a/tests/src/cmdline/rsvg_convert.rs b/tests/src/cmdline/rsvg_convert.rs
index 91ddb94c..36a764eb 100644
--- a/tests/src/cmdline/rsvg_convert.rs
+++ b/tests/src/cmdline/rsvg_convert.rs
@@ -481,23 +481,23 @@ fn x_and_y_resolution() {
 }
 
 #[test]
-fn defaults_are_used_for_zero_resolutions() {
+fn zero_resolution_is_invalid() {
     RsvgConvert::new_with_input("tests/fixtures/api/dpi.svg")
         .arg("--dpi-x=0")
         .arg("--dpi-y=0")
         .assert()
-        .success()
-        .stdout(file::is_png().with_size(90, 360));
+        .failure()
+        .stderr(contains("Invalid resolution"));
 }
 
 #[test]
-fn defaults_are_used_for_negative_resolutions() {
+fn negative_resolution_is_invalid() {
     RsvgConvert::new_with_input("tests/fixtures/api/dpi.svg")
         .arg("--dpi-x=-100")
         .arg("--dpi-y=-100")
         .assert()
-        .success()
-        .stdout(file::is_png().with_size(90, 360));
+        .failure()
+        .stderr(contains("Invalid resolution"));
 }
 
 #[test]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]