Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Hide some messages from the results window if the prefs for "Ignore X…

…HTML errors" or "Allow HTML 4.01 accessibility features" are set.

Encode HTML in results before displaying.
  • Loading branch information...
commit f3994f15ce215b34d1c249a971dea6052ef5f710 1 parent fc77ad1
Roger Johansson authored

Showing 1 changed file with 26 additions and 11 deletions. Show diff stats Hide diff stats

  1. 37  chrome/content/html5validator.js
37  chrome/content/html5validator.js
@@ -313,19 +313,18 @@ var html5validator = function()
313 313
 						message,
314 314
 						errors = 0, warnings = 0;
315 315
 					for (var i = 0; i < messages; i++) {
316  
-						// TODO: Remove hidden errors and warnings from the cached results to prevent them from showing up on the results page.
317 316
 						if (response.messages[i].type == "error") {
318  
-							// Do not count errors caused by an XHTML Doctype.
319  
-							// Not foolproof but matches XHTML 1.0 Strict/Transitional and 1.1 as long as no XML declaration is used.
320 317
 							if (preferences.ignoreXHTMLErrors) {
  318
+								// Do not count errors caused by an XHTML Doctype.
  319
+								// Not foolproof but matches XHTML 1.0 Strict/Transitional and 1.1 as long as no XML declaration is used.
321 320
 								message = response.messages[i];
322 321
 								if ((message.message.match(/^Legacy doctype./i) && message.extract.match(/<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.(1|0 Strict|0 Transitional)\/\/EN/i)) || message.message.match(/^Attribute “xml:lang” not allowed/i)) {
323 322
 									continue;
324 323
 								}
325 324
 							}
326  
-							// Do not count errors caused by removed accessibility features.
327  
-							// Currently allows the abbr, longdesc and scope attributes.
328 325
 							if (preferences.allowAccessibilityFeatures) {
  326
+								// Do not count errors caused by removed accessibility features.
  327
+								// Currently allows the abbr, longdesc and scope attributes.
329 328
 								message = response.messages[i];
330 329
 								if (message.message.match(/The “abbr” attribute on the “(td|th)” element is obsolete|The “longdesc” attribute on the “img” element is obsolete|The “scope” attribute on the “td” element is obsolete/i)) {
331 330
 									continue;
@@ -333,9 +332,9 @@ var html5validator = function()
333 332
 							}
334 333
 							errors++;
335 334
 						} else if (response.messages[i].subType == "warning") {
336  
-							// Do not count warnings caused by removed accessibility features.
337  
-							// Currently allows the summary attribute.
338 335
 							if (preferences.allowAccessibilityFeatures) {
  336
+								// Do not count warnings caused by removed accessibility features.
  337
+								// Currently allows the summary attribute.
339 338
 								message = response.messages[i];
340 339
 								if (message.message.match(/The “summary” attribute is obsolete/i)) {
341 340
 									continue;
@@ -414,7 +413,7 @@ var html5validator = function()
414 413
 
415 414
 		// Some CSS for styling the results. Plenty of room for improvement here.
416 415
 		var docCSS = generatedDocument.createElement('style');
417  
-		docCSS.appendChild(document.createTextNode('html {margin:0; padding:0; } body{ font: 100%/1.3 Arial, Helvetica, sans-serif; color:#222; background-color: #fff; margin: 1em; padding: 0;} h1 {font-size:1.5em;} li { margin:0 0 1px; padding:0.5em;} p {margin:0;} .info {background:#cff;} .warning {background:#ffc;} .error {background:#fcc;} .type {text-transform:capitalize;}'));
  416
+		docCSS.appendChild(document.createTextNode('html {margin:0; padding:0; } body{ font: 100%/1.3 Arial, Helvetica, sans-serif; color:#222; background-color: #fff; margin: 1em; padding: 0;} h1 {font-size:1.5em;} li { margin:0 0 1px; padding:0.5em;} p,pre {margin:0;} .info {background:#cff;} .warning {background:#ffc;} .error {background:#fcc;} .type {text-transform:capitalize;}'));
418 417
 		docHead.appendChild(docCSS);
419 418
 
420 419
 		// Create the HTML content of the body – a heading and the list of messages with some elements and class names to enable styling
@@ -425,19 +424,35 @@ var html5validator = function()
425 424
 		var message, li;
426 425
 		for (var i = 0, l = doc.validatorCache['messages'].length; i < l; i++) {
427 426
 			message = doc.validatorCache['messages'][i];
  427
+			if (preferences.ignoreXHTMLErrors) {
  428
+				// Do not show errors caused by an XHTML Doctype.
  429
+				// Not foolproof but matches XHTML 1.0 Strict/Transitional and 1.1 as long as no XML declaration is used.
  430
+				if ((message['message'].match(/^Legacy doctype./i) && message['extract'].match(/<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD XHTML 1.(1|0 Strict|0 Transitional)\/\/EN/i)) || message['message'].match(/^Attribute “xml:lang” not allowed/i)) {
  431
+					continue;
  432
+				}
  433
+			}
  434
+			if (preferences.allowAccessibilityFeatures) {
  435
+				// Do not show errors or warnings caused by removed accessibility features.
  436
+				// Currently allows the abbr, longdesc, summary and scope attributes.
  437
+				if (message['message'].match(/The “abbr” attribute on the “(td|th)” element is obsolete|The “longdesc” attribute on the “img” element is obsolete|The “scope” attribute on the “td” element is obsolete|The “summary” attribute is obsolete/i)) {
  438
+					continue;
  439
+				}
  440
+			}
428 441
 			li = errorList.appendChild(generatedDocument.createElement('li'));
429 442
 			li.className = message['type'] + (message['subType'] ? ' ' + message['subType'] : '');
430  
-			li.innerHTML = '<p><strong class="type">' + message['type'] + ':</strong> ' + message['message'] + '</p>';
  443
+			li.innerHTML = '<p><strong class="type">' + (message['subType'] ? ' ' + message['subType'] : message['type']) + ':</strong> ' + encodeHTML(message['message']) + '</p>';
431 444
 			if (message['lastLine']) {
432 445
 				li.innerHTML += '<p class="location">At line <span class="last-line">' + message['lastLine'] + '</span>, column <span class="first-col">' + message['firstColumn'] + '</span></p>';
433 446
 			}
434 447
 			if (message['extract']) {
435  
-				li.innerHTML += '<p class="extract"><code>' + message['extract'].replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;"); + '</code></p>';
  448
+				li.innerHTML += '<pre class="extract"><code>' + encodeHTML(message['extract']) + '</code></pre>';
436 449
 			}
437 450
 		}
  451
+	},
  452
+	encodeHTML = function(html) {
  453
+		return html.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;").replace(/>/g,"&gt;");
438 454
 	};
439 455
 
440  
-
441 456
 	return {
442 457
 		init: function ()
443 458
 		{

0 notes on commit f3994f1

Please sign in to comment.
Something went wrong with that request. Please try again.