Skip to content
Snippets Groups Projects
Commit 29d4e3f8 authored by Alexander Hass's avatar Alexander Hass
Browse files

Issue #2651180 by hass: Ignore fragment used for ajax requests

parent ba38c150
No related branches found
No related tags found
No related merge requests found
......@@ -614,17 +614,20 @@ function _linkchecker_status_handling(&$response, $link) {
$response->error = trim(drupal_convert_to_utf8($response->error, 'ISO-8859-1'));
$response->status_message = trim(drupal_convert_to_utf8($response->status_message, 'ISO-8859-1'));
// Destination anchors in HTML documents may be specified either by the A
// element (naming it with the name attribute), or by any other element
// (naming with the id attribute).
// Destination anchors in HTML documents may be specified either by:
// - the A element (naming it with the name attribute)
// - or by any other element (naming with the id attribute)
// - and must not contain a key/value pair as these type of hash fragments are
// typically used by AJAX applications to prevent additionally HTTP requests
// e.g. http://www.example.com/ajax.html#key1=value1&key2=value2
// - and must not contain '/' or ',' as this are not normal anchors.
// - and '#top' is a reserved fragment that must not exist in a page.
// See http://www.w3.org/TR/html401/struct/links.html
//
// Notes:
// - '#top' is a reserved fragment that must not exist in a page.
if ($response->code == 200
&& !empty($response->data)
&& !empty($response->headers['content-type'])
&& !empty($response->uri['fragment'])
&& preg_match('/=|\/|,/', $response->uri['fragment']) == FALSE
&& !in_array($response->uri['fragment'], array('#top'))
&& in_array($response->headers['content-type'], array('text/html', 'application/xhtml+xml', 'application/xml'))
&& !preg_match('/(\s[^>]*(name|id)(\s+)?=(\s+)?["\'])(' . preg_quote($response->uri['fragment'], '/') . ')(["\'][^>]*>)/i', $response->data)
......
......@@ -75,6 +75,8 @@ class LinkCheckerLinkExtractionTest extends DrupalWebTestCase {
<!-- URL with uncommon chars that could potentially fail to extract. See http://drupal.org/node/465462. -->
<a href="http://www.lagrandeepicerie.fr/#e-boutique/Les_produits_du_moment,2/coffret_vins_doux_naturels,149">URL with uncommon chars</a>
<a href="http://example.com/foo bar/is_valid-hack.test">URL with space</a>
<a href="http://example.com/ajax.html#key1=value1&key2=value2">URL with ajax query params</a>
<a href="http://example.com/test.html#test">URL with standard anchor</a>
<!-- object tag: Embed SWF files -->
<object width="150" height="116"
......@@ -227,6 +229,8 @@ EOT;
'http://v2v.cc/~j/theora_testsuite/pixel_aspect_ratio.mov',
'http://v2v.cc/~j/theora_testsuite/320x240.ogg',
'http://example.com/foo bar/is_valid-hack.test',
'http://example.com/ajax.html#key1=value1&key2=value2',
'http://example.com/test.html#test',
);
foreach ($urls_fqdn as $org_url => $check_url) {
......@@ -349,6 +353,8 @@ EOT;
'http://example.org/video/player3.swf',
'http://example.com/iframe/',
'http://example.com/foo bar/is_valid-hack.test',
'http://example.com/ajax.html#key1=value1&key2=value2',
'http://example.com/test.html#test',
);
foreach ($documentation_urls as $documentation_url) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment