diff --git a/changes.md b/changes.md index cdade5bc3..ae1d2cd2c 100644 --- a/changes.md +++ b/changes.md @@ -24,6 +24,7 @@ - Added "$hidden" static variable to the base Eloquent model. - Added "sync" method to has_many_and_belongs_to Eloquent relationship. - Improved View performance by only loading contents from file once. +- Fix handling of URLs beginning with has in URL::to. ## Upgrading From 3.1 diff --git a/laravel/url.php b/laravel/url.php index 9268a0d55..786a1bb2a 100644 --- a/laravel/url.php +++ b/laravel/url.php @@ -117,7 +117,13 @@ class URL { */ public static function to($url = '', $https = false) { - if (filter_var($url, FILTER_VALIDATE_URL) !== false) return $url; + // If the given URL is already valid or begins with a hash, we'll just return + // the URL unchanged since it is already well formed. Otherwise we will add + // the base URL of the application and return the full URL. + if (static::valid($url) or starts_with($url, '#')) + { + return $url; + } $root = static::base().'/'.Config::get('application.index'); @@ -310,4 +316,15 @@ class URL { return trim($uri, '/'); } + /** + * Determine if the given URL is valid. + * + * @param string $url + * @return bool + */ + public static function valid($url) + { + return filter_var($url, FILTER_VALIDATE_URL) !== false; + } + } \ No newline at end of file