Skip to content

Commit

Permalink
Item446: Make redirects aware of anchors in links
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@5966 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Jan 7, 2010
1 parent fb9b407 commit e87bfb8
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions core/lib/Foswiki.pm
Expand Up @@ -990,6 +990,22 @@ sub redirectto {

=begin TML
---++ StaticMethod splitAnchorFromUrl( $url ) -> ( $url, $anchor )
Takes a full url (including possible query string) and splits off the anchor.
The anchor includes the # sign. Returns an empty string if not found in the url.
=cut

sub splitAnchorFromUrl {
my ($url) = @_;

($url, my $anchor) = $url =~ m/^(.*?)(#(.*?))*$/;
return ( $url, $anchor );
}

=begin TML
---++ ObjectMethod redirect( $url, $passthrough )
* $url - url or topic to redirect to
Expand Down Expand Up @@ -1023,6 +1039,8 @@ sub redirect {

return unless $this->{request};

( $url, my $anchor ) = splitAnchorFromUrl($url);

if ( $passthru && defined $this->{request}->method() ) {
my $existing = '';
if ( $url =~ s/\?(.*)$// ) {
Expand Down Expand Up @@ -1055,7 +1073,7 @@ sub redirect {
}
}
}

# prevent phishing by only allowing redirect to configured host
# do this check as late as possible to catch _any_ last minute hacks
# TODO: this should really use URI
Expand All @@ -1076,6 +1094,8 @@ sub redirect {
);
}

#$url .= $anchor if $anchor;

return
if ( $this->{plugins}
->dispatch( 'redirectCgiQueryHandler', $this->{response}, $url ) );
Expand Down Expand Up @@ -1831,9 +1851,7 @@ sub i18n {

=begin TML
---++ ObjectMethod i18n()
Get a reference to the i18n object. Done lazily because not everyone
needs the i18ner.
---++ ObjectMethod logger()
=cut

Expand Down

0 comments on commit e87bfb8

Please sign in to comment.