Canonicalize URLs to be W3C compliant

The W3C feed validator (https://validator.w3.org/feed/) says that
http://cachet.example.org is not a valid value for a link, but that
http://cachet.example.org/ is.

The canonicalizeUrl method add a trailing slash if needed.
This commit is contained in:
Luc Didry
2015-06-12 23:03:42 +02:00
parent 7888f5953b
commit 3cde840e2b
2 changed files with 24 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ class AtomController extends AbstractController
$feed = Feed::make();
$feed->title = Setting::get('app_name');
$feed->description = trans('cachet.feed');
$feed->link = Setting::get('app_domain');
$feed->link = $this->canonicalizeUrl(Setting::get('app_domain'));
$feed->setDateFormat('datetime');
@@ -60,9 +60,19 @@ class AtomController extends AbstractController
$feed->add(
$incident->name,
Setting::get('app_name'),
Setting::get('app_domain'),
$this->canonicalizeUrl(Setting::get('app_domain')),
$incident->created_at->toAtomString(),
$incident->message
);
}
/**
* Add a / at the end of an URL to in order to be W3C compliant
*
* @param string $url
*/
private function canonicalizeUrl($url)
{
return preg_replace('/([^\/])$/', '$1/', $url);
}
}

View File

@@ -30,7 +30,7 @@ class RssController extends AbstractController
$feed = Feed::make();
$feed->title = Setting::get('app_name');
$feed->description = trans('cachet.feed');
$feed->link = Setting::get('app_domain');
$feed->link = $this->canonicalizeUrl(Setting::get('app_domain'));
$feed->setDateFormat('datetime');
@@ -60,9 +60,19 @@ class RssController extends AbstractController
$feed->add(
$incident->name,
Setting::get('app_name'),
Setting::get('app_domain'),
$this->canonicalizeUrl(Setting::get('app_domain')),
$incident->created_at->toRssString(),
$incident->message
);
}
/**
* Add a / at the end of an URL to in order to be W3C compliant
*
* @param string $url
*/
private function canonicalizeUrl($url)
{
return preg_replace('/([^\/])$/', '$1/', $url);
}
}