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/branches/Release01x00@5970 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Jan 7, 2010
1 parent 514f5fa commit 1a495cc
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions core/lib/Foswiki.pm
Expand Up @@ -852,6 +852,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 @@ -888,6 +904,8 @@ sub redirect {
# if we got here without a query, there's not much more we can do
return unless $query;

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

if ( $passthru && defined $query->method() ) {
my $existing = '';
if ( $url =~ s/\?(.*)$// ) {
Expand Down Expand Up @@ -942,6 +960,8 @@ sub redirect {
);
}

$url .= $anchor if $anchor;

return
if ( $this->{plugins}
->dispatch( 'redirectCgiQueryHandler', $this->{response}, $url ) );
Expand Down Expand Up @@ -1693,9 +1713,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 1a495cc

Please sign in to comment.