Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

FIX: Don't rewrite urls to be absolute, if they are a URI with a prot…

…ocol.

This is determined in this fix by the existence of a colon ':', to show the uri has a protocol.
  • Loading branch information...
commit d21fd1f0bbd6c654dfa2a3e9286524b51d548964 1 parent e0f4bd6
@jedateach jedateach authored
Showing with 35 additions and 6 deletions.
  1. +5 −1 control/HTTP.php
  2. +30 −5 tests/control/HTTPTest.php
View
6 control/HTTP.php
@@ -62,7 +62,11 @@ public static function filename2url($filename) {
public static function absoluteURLs($html) {
$html = str_replace('$CurrentPageURL', $_SERVER['REQUEST_URI'], $html);
return HTTP::urlRewriter($html, function($url) {
- if(stripos($url, 'mailto:') === 0) return $url;
+ //no need to rewrite, if uri has a protocol
+ //(determined here by existence of reserved URI character ":")
+ if(stripos($url, ":") !== false){
+ return $url;
+ }
return Director::absoluteURL($url, true);
});
}
View
35 tests/control/HTTPTest.php
@@ -173,6 +173,14 @@ public function testAbsoluteURLsAttributes() {
HTTP::absoluteURLs('<div background="./themes/silverstripe/images/nav-bg-repeat-2.png">SS Blog</div>')
);
+ //check dot segments
+ // Assumption: dots are not removed
+ //if they were, the url should be: http://www.silverstripe.org/abc
+ $test->assertEquals(
+ '<a href="http://www.silverstripe.org/test/page/../../abc">Test</a>',
+ HTTP::absoluteURLs('<a href="test/page/../../abc">Test</a>')
+ );
+
// image
$test->assertEquals(
'<img src=\'http://www.silverstripe.org/themes/silverstripe/images/logo-org.png\' />',
@@ -187,16 +195,33 @@ public function testAbsoluteURLsAttributes() {
});
}
- public function testEmailLinks() {
+ /**
+ * Make sure URI schemes are not rewritten
+ */
+ public function testURISchemes() {
$this->withBaseURL('http://www.silverstripe.org/', function($test){
-
- // links
+
+ // mailto
$test->assertEquals(
'<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>',
- HTTP::absoluteURLs('<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>')
+ HTTP::absoluteURLs('<a href=\'mailto:admin@silverstripe.org\'>Email Us</a>'),
+ 'Email links are not rewritten'
+ );
+
+ // data uri
+ $test->assertEquals(
+ '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />',
+ HTTP::absoluteURLs('<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot" />'),
+ 'Data URI links are not rewritten'
);
+
+ // call
+ $test->assertEquals(
+ '<a href="callto:12345678" />',
+ HTTP::absoluteURLs('<a href="callto:12345678" />'),
+ 'Call to links are not rewritten'
+ );
});
-
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.