From d90c0ae48f4419d3dad652e484f1a77ec08d8c81 Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@gmail.com>
Date: Mon, 16 Dec 2013 11:55:56 -0300
Subject: [PATCH] [PASSED QA] Bug 11402: Labels::_guide_box should return undef
 if undefned data is passed

That's it. A guide box cannot be created if invalid data is passed.

Sponsored-by: Universidad Nacional de Cordoba
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Passes all tests and QA script, includes new unit tests.
---
 C4/Labels/Label.pm |  2 ++
 t/Labels.t         | 14 ++++++++++++--
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/C4/Labels/Label.pm b/C4/Labels/Label.pm
index f62d50c..cb6a631 100644
--- a/C4/Labels/Label.pm
+++ b/C4/Labels/Label.pm
@@ -62,6 +62,8 @@ sub _check_params {
 
 sub _guide_box {
     my ( $llx, $lly, $width, $height ) = @_;
+    return unless ( defined $llx and defined $lly and
+                    defined $width and defined $height );
     my $obj_stream = "q\n";                            # save the graphic state
     $obj_stream .= "0.5 w\n";                          # border line width
     $obj_stream .= "1.0 0.0 0.0  RG\n";                # border color red
diff --git a/t/Labels.t b/t/Labels.t
index 823511b..0b2b804 100644
--- a/t/Labels.t
+++ b/t/Labels.t
@@ -20,7 +20,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 10;
 
 BEGIN {
     use_ok('C4::Labels::Label');
@@ -36,7 +36,17 @@ is_deeply($parsed_fields, $expected_fields, '"callnumber" in label layout alias
 
 is(C4::Labels::Label::_check_params(),"0",'test checking parameters');
 
-ok(C4::Labels::Label::_guide_box(), 'test guide box with nothing entered');
+my ($llx,$lly,$width,$height) = ( 0, 0, 10, 10 );
+ok(!defined C4::Labels::Label::_guide_box(),
+        "Test guide box with undefined parameters returns undef");
+ok(!defined C4::Labels::Label::_guide_box(undef,$lly,$width,$height),
+        "Test guide box with undefined 'x' coordinate returns undef");
+ok(!defined C4::Labels::Label::_guide_box($llx,undef,$width,$height),
+        "Test guide box with undefined 'y' coordinate returns undef");
+ok(!defined C4::Labels::Label::_guide_box($llx,$lly,undef,$height),
+        "Test guide box with undefined 'width' returns undef");
+ok(!defined C4::Labels::Label::_guide_box($llx,$lly,$width,undef),
+        "Test guide box with undefined 'height' returns undef");
 
 ok(C4::Labels::Label::_get_text_fields(), 'test getting textx fields');
 
-- 
1.8.3.2