Permalink
Browse files

Skip X<> tags when searching for titles in the pull parser.

Also strip out trailing whitespace that may result from ignoring X<> tags.
Resolves RT#74389, and per discussion on pod-people, archived here:

  http://code.activestate.com/lists/perl-pod-people/1698/
  • Loading branch information...
1 parent 015f0d0 commit a2047c42501c47f8fe8ff610f7f4cf65616ec54e @theory committed Feb 14, 2013
Showing with 25 additions and 6 deletions.
  1. +4 −0 ChangeLog
  2. +12 −5 lib/Pod/Simple/PullParser.pm
  3. +9 −1 t/pulltitl.t
View
@@ -47,6 +47,10 @@
maps to "pre", and "teletype" maps to "tt". Suggested by Robert
Boisvert (RT #79201).
+ "X< >" tags are now ignored by the pull parser when it searches
+ for titles, as is any trailing whitespace. Thanks to Patrice Dumas
+ for the report (RT #74389).
+
2012-08-14 David E. Wheeler <david@justatheory.org>
* Release 3.23
@@ -347,6 +347,7 @@ sub _get_titled_section {
my $head1_text_content;
my $para_text_content;
+ my $skipX;
while(
++$token_count <= ($max_token || 1_000_000)
@@ -364,8 +365,14 @@ sub _get_titled_section {
elsif($state == 1) { # accumulating text until end of head1
if( $token->is_text ) {
- DEBUG and print " Adding \"", $token->text, "\" to head1-content.\n";
- $head1_text_content .= $token->text;
+ unless ($skipX) {
+ DEBUG and print " Adding \"", $token->text, "\" to head1-content.\n";
+ $head1_text_content .= $token->text;
+ }
+ } elsif( $token->is_tagname('X') ) {
+ # We're going to want to ignore X<> stuff.
+ $skipX = $token->is_start;
+ DEBUG and print +($skipX ? 'Start' : 'End'), 'ing ignoring of X<> tag';
} elsif( $token->is_end and $token->tagname eq 'head1' ) {
DEBUG and print " Found end of head1. Considering content...\n";
$head1_text_content = uc $head1_text_content if $nocase;
@@ -392,9 +399,9 @@ sub _get_titled_section {
? (length($head1_text_content) <= $max_content_length) # sanity
: 1)
) {
- DEBUG and print " It looks titular: \"$head1_text_content\".\n",
- "\n Using that.\n";
- $title = $head1_text_content;
+ # Looks good; trim it
+ ($title = $head1_text_content) =~ s/\s+$//;
+ DEBUG and print " It looks titular: \"$title\".\n\n Using that.\n";
last;
} else {
--$state;
View
@@ -7,7 +7,7 @@ BEGIN {
use strict;
use Test;
-BEGIN { plan tests => 116 };
+BEGIN { plan tests => 117 };
#use Pod::Simple::Debug (5);
@@ -408,6 +408,14 @@ ok( $t && $t->type eq 'start' && $t->tagname, 'Document' );
}
###########################################################################
+{
+print "# Testing a title with an X<>, at line ", __LINE__, "\n";
+my $p = Pod::Simple::PullParser->new;
+$p->set_source( \qq{\n=head1 NAME Foo Bar\nX<Some entry>\n} );
+
+ok $p->get_title(), 'NAME Foo Bar';
+}
+
###########################################################################

0 comments on commit a2047c4

Please sign in to comment.