Changeset 3974


Ignore:
Timestamp:
05/24/09 12:15:55 (3 years ago)
Author:
CrawfordCurrie
Message:

Item1603: use quotes to protect topic names with odd characters in them

Location:
trunk/MailerContrib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/MailerContrib/data/System/MailerContrib.txt

    r3639 r3974  
    163163|  Version: | %$VERSION% | 
    164164|  Change History: | | 
     165|  24 May 2009 | Foswikitask:Item1603: use quotes to protect topic names with odd characters in them | 
    165166|  23 Apr 2009 | Foswikitask:Item1501: Minor bug in logfile output fixed | 
    166167|  03 Dec 2008 | Re-released for the Foswiki project | 
  • trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib.pm

    r3947 r3974  
    133133    }; 
    134134 
    135     my $ret = Foswiki::Contrib::MailerContrib::parsePageList( $subscribed, $who, 
    136         $topicList ); 
     135    my $ret = parsePageList( $subscribed, $who, $topicList ); 
    137136 
    138137    return ( !defined( $subscribed->{not_subscribed} ) 
     
    165164        push( @{ $subscribed->{not_subscribed} }, $stopic ); 
    166165    } 
    167     return ''; 
    168166} 
    169167 
    170168=pod 
     169 
    171170---+++ sub parsePageList ( $object, $who, $spec, $unsubscribe ) => unprocessable remainder of $spec line 
    172 calls the $topicSub (ref to sub) once per identified topic entry. 
    173    * $object (is a hashref) can be used to set status' and its definition is dependent on $topicSub 
    174    * $object->{topicSub} _must_ be a sub ref and _must_ return an empty string 
    175    * $unsubscribe can be set to '-' to force an unsubscription (used by SubscribePlugin) 
    176     
    177    $object is a functor. 
     171Calls the $object->{topicSub} once per identified topic entry. 
     172   * $object (a hashref) may be a hashref that has the field, =topicSub=, 
     173     which _may_ be a sub ref as follows: 
     174     =&topicSub($object, $who, $unsubscribe, $webTopic, $options, $childDepth)= 
     175   * =$unsubscribe= can be set to '-' to force an unsubscription 
     176     (used by SubscribePlugin) 
    178177 
    179178=cut 
     
    184183    #ASSERT(defined($object->{topicSub})); 
    185184 
    186     return $spec if ( !defined( $object->{topicSub} ) ); 
     185    return $spec if ( !$object || !defined( $object->{topicSub} ) ); 
    187186 
    188187    $spec =~ s/,/ /g; 
    189188 
    190     #TODO: refine the $2 regex to be proper web.topic/topic/* style.. 
     189    # $1: + or -, optional 
     190    # $2: the wildcarded topic specifier (may be quoted) 
     191    # TODO: refine the $2 regex to be proper web.topic/topic/* style.. 
     192    # $3: options 
     193    # $4: child depth 
    191194    while ( $spec =~ 
    192 s/^\s*([+-])?\s*([\w.\*]+)([!?]?)\s*(?:\((\d+)\))?/&{$object->{topicSub}}($object, $who, $unsubscribe||$1, $2, $3, $4)/e 
    193       ) 
    194     { 
    195  
     195              s/^\s*([+-])?\s*([*\w.]+|'.*?'|".*?")([!?]?)\s*(?:\((\d+)\))?//) { 
     196        my ( $us, $webTopic, $options, $childDepth ) = ( 
     197            $unsubscribe||$1||'+', $2, $3, $4||0 ); 
     198        $webTopic =~ s/^(['"])(.*)\1$/$2/; # remove quotes 
     199        &{$object->{topicSub}}( 
     200            $object, $who, $us, $webTopic, $options, $childDepth); 
    196201        #go 
    197202    } 
     
    205210    if ( !Foswiki::Func::webExists($web) ) { 
    206211 
    207         #        print STDERR "**** ERROR mailnotifier cannot find web $web\n"; 
     212        # print STDERR "**** ERROR mailnotifier cannot find web $web\n"; 
    208213        return ''; 
    209214    } 
  • trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib/Subscription.pm

    r2957 r3974  
    6868    my $record = $this->{topics}; 
    6969 
    70     # convert RE back to wildcard 
    71     $record =~ s/\.\*\?/\*/; 
     70    # Protect non-alphanumerics in topic name 
     71    if ($record =~ /[^*\w.]/) { 
     72        if ($record =~ /'/) { 
     73            $record = "\"$record\""; 
     74        } else { 
     75            $record = "'$record'"; 
     76        } 
     77    } 
    7278    $record .= $this->getMode(); 
    7379    $record .= " ($this->{depth})" if ( $this->{depth} ); 
  • trunk/MailerContrib/lib/Foswiki/Contrib/MailerContrib/WebNotify.pm

    r3639 r3974  
    417417    $this->{topicSub} = \&_subscribeTopic; 
    418418 
    419     my $ret = 
    420       Foswiki::Contrib::MailerContrib::parsePageList( $this, $who, $spec, 
    421         $unsubscribe ); 
     419    my $ret = Foswiki::Contrib::MailerContrib::parsePageList( 
     420        $this, $who, $spec, $unsubscribe ); 
    422421    if ( $ret =~ m/\S/ ) { 
    423         Foswiki::Func::writeWarning("Badly formatted page list at $who: $spec"); 
     422        Foswiki::Func::writeWarning( 
     423            "Badly formatted page list at $who: $spec"); 
    424424        return -1; 
    425425    } 
  • trunk/MailerContrib/test/unit/MailerContrib/MailerContribSuite.pm

    r3944 r3974  
    2020    TestTopic122  => "r1->r2", 
    2121    TestTopic1221 => "r1->r2", 
    22     TestTopic2    => "r2->r3", 
    23     TestTopic21   => "r1->r2", 
     22    'TestTopic2'    => "r2->r3", 
     23    'TestTopic21'   => "r1->r2", 
    2424); 
    2525 
     
    3434    TestTopic122  => "That danged robot", 
    3535    TestTopic1221 => "What's up, Buck?", 
    36     TestTopic2    => "roast my nipple-nuts", 
    37     TestTopic21   => "smoke me a kipper, I'll be back for breakfast", 
     36    'TestTopic2'    => "roast my nipple-nuts", 
     37    'TestTopic21'   => "smoke me a kipper, I'll be back for breakfast", 
    3838 
    3939    # High-bit chars - assumes {Site}{CharSet} is set for a high-bit 
     
    145145        { 
    146146            email     => "email4\@example.com", 
    147             entry     => "email4\@example.com: TestTopic1 (0), TestTopic2 (3)", 
     147            entry     => "email4\@example.com: TestTopic1 (0), 'TestTopic2' (3)", 
    148148            topicsout => "TestTopic1 TestTopic2 TestTopic21" 
    149149        }, 
     
    153153            email => "email5\@example.com", 
    154154            entry => 
    155               "email5\@example.com: TestTopic1 + TestTopic2(3), -TestTopic21", 
     155              "email5\@example.com: TestTopic1 + 'TestTopic2'(3), -'TestTopic21'", 
    156156            topicsout => "TestTopic1 TestTopic2" 
    157157        }, 
     
    167167        { 
    168168            email => "email7\@example.com", 
    169             entry => "email7\@example.com: TestTopic*1 - \\\n   TestTopic2*", 
     169            entry => "email7\@example.com: TestTopic*1 - \\\n   'TestTopic2*'", 
    170170            topicsout => "TestTopic1 TestTopic11 TestTopic121", 
    171171        }, 
     
    338338        ( $meta, $text ) = Foswiki::Func::readTopic( $web, "TestTopic2" ); 
    339339        Foswiki::Func::saveTopic( $web, "TestTopic2", $meta, 
    340             $finalText{TestTopic2}, { forcenewrevision => 1 } ); 
     340            $finalText{'TestTopic2'}, { forcenewrevision => 1 } ); 
    341341 
    342342        ( $meta, $text ) = Foswiki::Func::readTopic( $web, "TestTopic21" ); 
    343343        Foswiki::Func::saveTopic( $web, "TestTopic21", $meta, 
    344             $finalText{TestTopic21}, { forcenewrevision => 1 } ); 
     344            $finalText{'TestTopic21'}, { forcenewrevision => 1 } ); 
    345345 
    346346        # wait a wee bit more for the clock to tick over again 
Note: See TracChangeset for help on using the changeset viewer.