Ignore:
Timestamp:
12/09/08 18:16:48 (3 years ago)
Author:
CrawfordCurrie
Message:

Item253: remove TWikiDrawPlugin hack; analyse, rationalise and document usage of redirectto; Item5926: added encodings that were proposed to make chinese work (they don't break anything AFAICT). Deprecate Foswiki::Func::getRegularExpression (the regex array is published)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/Foswiki.pm

    r1206 r1221  
    407407    $regex{anchorRegex}         = qr/\#[$regex{mixedAlphaNum}_]+/o; 
    408408    $regex{abbrevRegex}         = qr/[$regex{upperAlpha}]{3,}s?\b/o; 
    409  
     409    $regex{topicNameRegex}      = 
     410      qr/(?:(?:$regex{wikiWordRegex})|(?:$regex{abbrevRegex}))/o; 
    410411    # Simplistic email regex, e.g. for WebNotify processing - no i18n 
    411412    # characters allowed 
     
    724725} 
    725726 
    726 =begin TML 
    727  
    728 ---++ StaticMethod isRedirectSafe($redirect) => $ok 
    729  
    730 tests if the $redirect is an external URL, returning false if AllowRedirectUrl is denied 
    731  
    732 =cut 
    733  
    734 sub isRedirectSafe { 
     727# Tests if the $redirect is an external URL, returning false if 
     728# AllowRedirectUrl is denied 
     729sub _isRedirectSafe { 
    735730    my $redirect = shift; 
    736731 
     
    758753} 
    759754 
    760 # _getRedirectUrl() => redirectURL set from the parameter 
    761 # Reads a redirect url from CGI parameter 'redirectto'. 
    762 # This function is used to get and test the 'redirectto' cgi parameter, 
    763 # and then the calling function can set its own reporting if there is a 
    764 # problem. 
    765 sub _getRedirectUrl { 
    766     my $session = shift; 
    767  
    768     my $query       = $session->{request}; 
    769     my $redirecturl = $query->param('redirectto'); 
    770     return '' unless $redirecturl; 
     755=begin TML 
     756 
     757---++ ObjectMethod redirectto($url) -> $url 
     758Gets a redirect url from CGI parameter 'redirectto', if present on the query. 
     759 
     760If the redirectto CGI parameter specifies a valid redirection target it is 
     761returned; otherwise the original URL passed in the parameter is returned. 
     762 
     763Conditions for a valid redirection target are: 
     764   * The target matches the linkProtocolPattern regex, and redirection 
     765     to the url _isRedirectSafe 
     766   * The target specified a topic, or a Web.Topic (redirect will be to 
     767     'view') 
     768 
     769=cut 
     770 
     771sub redirectto { 
     772    my ($this, $url) = @_; 
     773    ASSERT($url); 
     774 
     775    my $redirecturl = $this->{request}->param('redirectto'); 
     776    return $url unless $redirecturl; 
    771777 
    772778    if ( $redirecturl =~ m#^$regex{linkProtocolPattern}://#o ) { 
    773779 
    774780        # assuming URL 
    775         if ( isRedirectSafe($redirecturl) ) { 
     781        if ( _isRedirectSafe($redirecturl) ) { 
    776782            return $redirecturl; 
    777783        } 
    778784        else { 
    779             return ''; 
     785            return $url; 
    780786        } 
    781787    } 
     
    783789    # assuming 'web.topic' or 'topic' 
    784790    my ( $w, $t ) = 
    785       $session->normalizeWebTopicName( $session->{webName}, $redirecturl ); 
    786     $redirecturl = $session->getScriptUrl( 1, 'view', $w, $t ); 
    787     return $redirecturl; 
    788 } 
    789  
    790 =begin TML 
    791  
    792 ---++ ObjectMethod redirect( $url, $passthrough, $action_redirectto ) 
     791      $this->normalizeWebTopicName( $this->{webName}, $redirecturl ); 
     792    return $this->getScriptUrl( 1, 'view', $w, $t ); 
     793} 
     794 
     795=begin TML 
     796 
     797---++ ObjectMethod redirect( $url, $passthrough ) 
    793798 
    794799   * $url - url or topic to redirect to 
    795    * $passthrough - (optional) parameter to **FILLMEIN** 
    796    * $action_redirectto - (optional) redirect to where ?redirectto= 
    797      points to (if it's valid) 
     800   * $passthrough - (optional) parameter to pass through current query 
     801     parameters (see below) 
    798802 
    799803Redirects the request to =$url=, *unless* 
    800804   1 It is overridden by a plugin declaring a =redirectCgiQueryHandler=. 
    801805   1 =$session->{request}= is =undef= or 
    802    1 $query->param('noredirect') is set to a true value. 
    803806Thus a redirect is only generated when in a CGI context. 
    804807 
     
    820823 
    821824sub redirect { 
    822     my ( $this, $url, $passthru, $action_redirectto ) = @_; 
     825    my ( $this, $url, $passthru ) = @_; 
     826    ASSERT(defined $url); 
    823827 
    824828    my $query = $this->{request}; 
     
    826830    # if we got here without a query, there's not much more we can do 
    827831    return unless $query; 
    828  
    829     # SMELL: if noredirect is set, don't generate the redirect, throw an 
    830     # exception instead. This is a HACK used to support TWikiDrawPlugin. 
    831     # It is deprecated and must be replaced by REST handlers in the plugin. 
    832     if ( $query->param('noredirect') ) { 
    833         die "ERROR: $url"; 
    834         return; 
    835     } 
    836  
    837     if ($action_redirectto) { 
    838         my $redir = _getRedirectUrl($this); 
    839         $url = $redir if ($redir); 
    840     } 
    841832 
    842833    if ( $passthru && defined $query->method() ) { 
     
    872863    # do this check as late as possible to catch _any_ last minute hacks 
    873864    # TODO: this should really use URI 
    874     if ( !isRedirectSafe($url) ) { 
     865    if ( !_isRedirectSafe($url) ) { 
    875866 
    876867        # goto oops if URL is trying to take us somewhere dangerous 
     
    962953    my ($name) = @_; 
    963954 
    964     return isValidWikiWord(@_) || isValidAbbrev(@_); 
    965 } 
    966  
    967 =begin TML 
    968  
    969 ---++ StaticMethod isValidAbbrev( $name ) -> $boolean 
    970  
    971 Check for a valid ABBREV (acronym) 
    972  
    973 =cut 
    974  
    975 sub isValidAbbrev { 
    976     my $name = shift || ''; 
    977     return ( $name =~ m/^$regex{abbrevRegex}$/o ); 
     955    return ( $name =~ m/^$regex{topicNameRegex}$/o ); 
    978956} 
    979957 
     
    11481126    while ( my $p = shift @args ) { 
    11491127        if ( $p eq '#' ) { 
    1150             $anchor .= '#' . shift(@args); 
     1128            $anchor .= '#' . urlEncode( shift(@args) ); 
    11511129        } 
    11521130        else { 
     
    38593837        # Issues multi-valued parameters as separate hiddens 
    38603838        my $value = $this->{request}->param($name); 
     3839        $value = '' unless defined $value; 
    38613840        $name = _encode( $encoding, $name ); 
    38623841        $value = _encode( $encoding, $value ); 
Note: See TracChangeset for help on using the changeset viewer.