Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Eliminate `undef` warnings. #19

Open
wants to merge 2 commits into from

1 participant

@theory

I’ve found that Text::Markup sometimes is asked to parse an empty file. It opens it and passes do { local $/; <$fh> } to Text::Markdown. So an undef gets passed, resulting in these warnings:

Use of uninitialized value $text in substitution (s///) at /usr/local/perl/lib/site_perl/5.14.2/Text/Markdown.pm line 270.
Use of uninitialized value $text in substitution (s///) at /usr/local/perl/lib/site_perl/5.14.2/Text/Markdown.pm line 271.

This patch eliminates that warning, and adds tests for it, as well.

Thanks,

David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 16, 2012
  1. @theory

    Eliminate `undef` warnings.

    theory authored
  2. @theory

    Update plan.

    theory authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +1 −0  Makefile.PL
  2. +3 −0  lib/Text/Markdown.pm
  3. +9 −0 t/05empty_markdown.t
View
1  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) {
View
3  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
View
9 t/05empty_markdown.t
@@ -0,0 +1,9 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+use Text::Markdown;
+use Test::NoWarnings;
+
+my $m = Text::Markdown->new;
+ok $m->markdown(''), 'Parse empty string';
+ok $m->markdown(undef), 'Parse undef';
Something went wrong with that request. Please try again.