From e0c1e3493f022231889dd41f48652def24a6ae8f Mon Sep 17 00:00:00 2001
From: Gianni Ceccarelli <gianni.ceccarelli@broadbean.com>
Date: Wed, 3 Jun 2020 09:59:37 +0100
Subject: [PATCH] fix & tests for #70927
---
lib/HTML/Defang.pm | 2 +-
t/01_basic.t | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/HTML/Defang.pm b/lib/HTML/Defang.pm
index 8520e56..60af9b1 100644
--- a/lib/HTML/Defang.pm
+++ b/lib/HTML/Defang.pm
@@ -1416,7 +1416,7 @@ sub defang {
warn "defang OutputRemainder" if $Debug;
$I =~ m/\G(.*)$/gcs;
- $$OutR .= $1 if $1;
+ $$OutR .= $1 if defined $1;
# Exit if we got here
last;
diff --git a/t/01_basic.t b/t/01_basic.t
index 7759011..9d96ee5 100755
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -4,7 +4,7 @@ BEGIN { # CPAN users don't have ME::*, so use eval
eval 'use ME::FindLibs'
}
-use Test::More tests => 93;
+use Test::More tests => 98;
use HTML::Defang;
use strict;
@@ -13,6 +13,21 @@ my ($DefangString, $CommentStartText, $CommentEndText) = ('defang_', '/\*SC\*/',
my $Defang = HTML::Defang->new();
+$H = ''; $Res =$Defang->defang($H);
+is($Res, '', 'empty string should stay as-is');
+
+$H = ' '; $Res =$Defang->defang($H);
+is($Res, ' ', 'whitespace should stay as-is');
+
+$H = '0'; $Res =$Defang->defang($H);
+is($Res, '0', 'zero-as-a-string should stay as-is');
+
+$H = '00'; $Res =$Defang->defang($H);
+is($Res, '00', 'zero-zero should stay as-is');
+
+$H = 0; $Res =$Defang->defang($H);
+is($Res, '0', 'zero-as-a-number (weird) should stay as-is');
+
$H = <<EOF;
1:<html>
2:<head>
--
2.26.2