You are here: Foswiki>Tasks Web>Item5969 (31 Jan 2018, GeorgeClark)Edit Attach

Item5969: Support IPv6 addresses in Square Bracket links

pencil
Priority: Enhancement
Current State: Waiting for Release
Released In: 2.2.0
Target Release: minor
Applies To: Engine
Component: UrlHandling
Branches: master Item14288 Item14380 Item14537
Reported By: TWiki:Main.JoaoMadrid
Waiting For:
Last Change By: GeorgeClark
It seems that TWiki doesn't support ipv6 addresses in url (e.g. http://[2001:50ff:0:4004::f5f5]/twiki/bin/view/)

When we type an ipv6 addresse in url bar, TWiki doesn't recognize brackets. It generates all internal links in the page source as follows:

http://%5B2001:50ff:0:4004::f5f5%5D/twiki/pub/TWiki/...

Obs1: The use of brackets in ipv6 addresses is required.

Obs2: If site is accessed by name, the problem does not occur.

-- TWiki:Main/JoaoMadrid - 29 Aug 2008

That's correct, it doesn't support ipv6 addresses. There has been no demand for this before now. I suspect it would be quite tricky to do, so there would need to be a very good reason to support them.

Reclassified as Enhancement and Confirmed.

-- TWiki:Main.CrawfordCurrie - 30 Aug 2008

We believe that the imminent end of IPv4 addresses, forecast to 2011, is a very good reason to support IPv6.

We are using TWiki to develop a website for supporting and promoting the adoption of IPv6 in Brazil (http://ipv6.br). Today, the website is based on Joomla, however, we are switching to TWiki because it fits better. However, a client must rely on DNS system to be able to view the website.

We need to solve this issue. We could help solving this, but we don't have previous experience with twiki code. If someone could give us some hints, we would be glad to work on it.

The following are some sites with papers about the end of the IPv4 and the deployment of IPv6:

http://www.arin.net/v6/v6-info.html http://portalipv6.lacnic.net/en http://lacnic.net/ipv6/en/ http://www.ipv6.org/ http://www.ipv6tf.org

-- TWiki:Main.JoaoMadrid - 01 Sep 2008

Try to use foswiki with ipv6... wikiword, are functional, but the following piece of code is not render as hyperlink :
[[MyLink][my text]]
is render as : [[[[http://[2a01:...

the [ code need for the ipv6 (as https://www.ietf.org/rfc/rfc2732.txt ) seems to break the render of the hyperlink.

-- GuilainCabannes - 19 Feb 2015

The following fix works on 2.0 & 2.1. Won't fit on 1.1. Adds a dependency on another CPAN module: CPAN:Regexp::IPv6

diff --git a/core/lib/Foswiki/Render.pm b/core/lib/Foswiki/Render.pm
index 759f13d..4654a06 100644
--- a/core/lib/Foswiki/Render.pm
+++ b/core/lib/Foswiki/Render.pm
@@ -520,11 +520,23 @@ qr/<[Tt][Ee][Xx][Tt][Aa][Rr][Ee][Aa]\b.*?<\/[Tt][Ee][Xx][Tt][Aa][Rr][Ee][Aa]>/s,
     # Change ' ![[...' to ' [<nop>[...' to protect from further rendering
     $text =~ s/(^|\s)\!\[\[/$1\[<nop>\[/gm;
 
+    my $remove_v6 = {};
+    if ( eval 'require Regexp::IPv6' ) {
+
+        # Remove IPv6 addresses,  as they break square bracket links.
+        $text =
+          $this->_takeOutProtected( $text, qr/\[$Regexp::IPv6::IPv6_re\]/s,
+            'ipv6', $remove_v6 );
+    }
+
     # Spaced-out Wiki words with alternative link text
     # i.e. [[$1][$3]]
     $text =~ s(\[\[([^\]\[\n]+)\](\[([^\]\n]+)\])?\])
         (_handleSquareBracketedLink( $this,$topicObject,$1,$3))ge;
 
+    $this->_putBackProtected( \$text, 'ipv6', $remove_v6 )
+      if ( scalar $remove_v6 );
+
     # URI - don't apply if the URI is surrounded by url() to avoid naffing
     # CSS
     $text =~ s/(^|(?<!url)[-*\s(|])
@@ -1794,7 +1806,8 @@ sub _putBackProtected {
         # Reset position for next pass
         $pos = 0;
 
-        delete( $map->{$placeholder} );
+        #SMELL: Can't do this, [[links]] might duplicate placeholders
+        #delete( $map->{$placeholder} );
     }
 
     $ntext .= $otext;    # Append any remaining text.

And after consideration, I don't really think that this is the way to handle this. The IPv6 regex is very complex, and has the risk of matching too much. There are other breakages as well, for ex, when a query string contains square brackets.
https://metacpan.org/requires/distribution/Moo?sort=[[2,1]]&size=500
We probably would have to move away from regex based parsing to fix this.

-- GeorgeClark - 09 Jan 2016 - 02:34

Links with square brackets in the query string don't work, with or without the IPv6 changes. Solution is to URL encode them as %5B and %5D

https://metacpan.org/requires/distribution/Moo?sort=%5B%5B2,1%5D%5D&size=500

-- GeorgeClark - 29 Mar 2017

-- GeorgeClark - 29 Mar 2017

Note that the Squab link in this test will only work if CPAN:Regexp::IPv6 is installed.

-- GeorgeClark - 29 Mar 2017
 

ItemTemplate edit

Summary Support IPv6 addresses in Square Bracket links
ReportedBy TWiki:Main.JoaoMadrid
Codebase 2.1.4, trunk
SVN Range TWiki-5.0.0, Mon, 18 Aug 2008, build 17431
AppliesTo Engine
Component UrlHandling
Priority Enhancement
CurrentState Waiting for Release
WaitingFor
Checkins distro:88088d7f0c6d
TargetRelease minor
ReleasedIn 2.2.0
CheckinsOnBranches master Item14288 Item14380 Item14537
trunkCheckins
masterCheckins distro:88088d7f0c6d
ItemBranchCheckins distro:88088d7f0c6d
Release02x01Checkins
Release02x00Checkins
Release01x01Checkins
Topic revision: r15 - 31 Jan 2018, GeorgeClark
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy