From 973391222fbb5d72ffd2d469a221baffa10e0415 Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 16 Jan 2012 10:58:24 -0800 Subject: [PATCH 1/2] Eliminate `undef` warnings. --- Makefile.PL | 1 + lib/Text/Markdown.pm | 3 +++ t/05empty_markdown.t | 10 ++++++++++ 3 files changed, 14 insertions(+) create mode 100644 t/05empty_markdown.t diff --git a/Makefile.PL b/Makefile.PL index 9c8f66f..b324098 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,7 @@ test_requires 'Test::More' => '0.42'; test_requires 'Test::Exception' => undef; test_requires 'List::MoreUtils' => undef; test_requires 'Test::Differences' => undef; +test_requires 'Test::NoWarnings' => undef; test_requires 'FindBin' => undef; if ($Module::Install::AUTHOR) { diff --git a/lib/Text/Markdown.pm b/lib/Text/Markdown.pm index 1c1f93e..1821315 100644 --- a/lib/Text/Markdown.pm +++ b/lib/Text/Markdown.pm @@ -266,6 +266,9 @@ sub urls { sub _CleanUpDoc { my ($self, $text) = @_; + # An empty file can end up getting passed as undef. + return "\n\n" unless defined $text; + # Standardize line endings: $text =~ s{\r\n}{\n}g; # DOS to Unix $text =~ s{\r}{\n}g; # Mac to Unix diff --git a/t/05empty_markdown.t b/t/05empty_markdown.t new file mode 100644 index 0000000..b4beafd --- /dev/null +++ b/t/05empty_markdown.t @@ -0,0 +1,10 @@ +use strict; +use warnings; +#use Test::More tests => 21; +use Test::More 'no_plan'; +use Text::Markdown; +use Test::NoWarnings; + +my $m = Text::Markdown->new; +ok $m->markdown(''), 'Parse empty string'; +ok $m->markdown(undef), 'Parse undef'; From 984f5e9d4d699e6f1b63ee2df6c79086c1d1d29a Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Mon, 16 Jan 2012 11:01:47 -0800 Subject: [PATCH 2/2] Update plan. --- t/05empty_markdown.t | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/t/05empty_markdown.t b/t/05empty_markdown.t index b4beafd..b3aaf72 100644 --- a/t/05empty_markdown.t +++ b/t/05empty_markdown.t @@ -1,7 +1,6 @@ use strict; use warnings; -#use Test::More tests => 21; -use Test::More 'no_plan'; +use Test::More tests => 3; use Text::Markdown; use Test::NoWarnings;