diff --git a/code/sitefeatures/PageComment.php b/code/sitefeatures/PageComment.php index e0981c3e..9067d0f7 100755 --- a/code/sitefeatures/PageComment.php +++ b/code/sitefeatures/PageComment.php @@ -150,16 +150,11 @@ class PageComment extends DataObject { $url = $this->CommenterURL; if($url) { - if(substr($url, 0, 8) != 'https://') { - if(substr($url, 0, 7) != 'http://') { - $url = $this->CommenterURL = 'http://' . $url; - } + if(strtolower(substr($url, 0, 8)) != 'https://' && strtolower(substr($url, 0, 7)) != 'http://') { + $this->CommenterURL = 'http://' . $url; } } - - $this->CommenterURL = $url; } - } diff --git a/tests/PageCommentsTest.php b/tests/PageCommentsTest.php index b4c08976..fa57b991 100644 --- a/tests/PageCommentsTest.php +++ b/tests/PageCommentsTest.php @@ -27,5 +27,21 @@ class PageCommentsTest extends FunctionalTest { $thirdComments = DataObject::get('PageComment', 'ParentID = '.$third->ID); $this->assertEquals($thirdComments->Count(), 3); } + + function testCommenterURLWrite() { + $comment = new PageComment(); + // We only care about the CommenterURL, so only set that + // Check a http and https URL. Add more test urls here as needed. + $protocols = array( + 'Http', + 'Https', + ); + $url = '://example.com'; + foreach($protocols as $protocol) { + $comment->CommenterURL = $protocol . $url; + // The protocol should stay as if, assuming it is valid + $comment->write(); + $this->assertEquals($comment->CommenterURL, $protocol . $url, $protocol . ':// is a valid protocol'); + } + } } -?>