Skip to content

Commit

Permalink
Fix failing test in Router
Browse files Browse the repository at this point in the history
Update plainstring tests to account for various types of relative links
that don't resolve to routes. Those include urls with leading //, ://,
?, and #.
  • Loading branch information
markstory committed Jul 10, 2013
1 parent 740513c commit f8a72c9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Cake/Routing/Router.php
Expand Up @@ -692,18 +692,20 @@ public static function url($url = null, $options = array()) {
list($full, $options) = array($options, array());
}
$urlType = gettype($url);
$hasColonSlash = $hasLeadingSlash = $plainString = false;
$hasLeadingSlash = $plainString = false;

if ($urlType === 'string') {
$plainString = (
strpos($url, 'javascript:') === 0 ||
strpos($url, 'mailto:') === 0 ||
strpos($url, 'tel:') === 0 ||
strpos($url, 'sms:') === 0 ||
strpos($url, '#') === 0
strpos($url, '#') === 0 ||
strpos($url, '?') === 0 ||
strpos($url, '//') === 0 ||
strpos($url, '://') !== false
);

$hasColonSlash = strpos($url, '://') !== false;
$hasLeadingSlash = isset($url[0]) ? $url[0] === '/' : false;
}

Expand Down Expand Up @@ -777,7 +779,6 @@ public static function url($url = null, $options = array()) {
} elseif (
$urlType === 'string' &&
!$hasLeadingSlash &&
!$hasColonSlash &&
!$plainString
) {
// named route.
Expand All @@ -796,7 +797,7 @@ public static function url($url = null, $options = array()) {
$output = static::$_routes->match($url);
} else {
// String urls.
if ($hasColonSlash || $plainString) {
if ($plainString) {
return $url;
}
$output = $url;
Expand Down

0 comments on commit f8a72c9

Please sign in to comment.