testaro 40.0.2 → 41.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -40,6 +40,8 @@ const cap = rawString => {
40
40
  return '';
41
41
  }
42
42
  };
43
+ // Returns whether an id attribute value is valid without character escaping.
44
+ const isBadID = id => /[^-\w]|^\d|^--|^-\d/.test(id);
43
45
  // Returns the tag name and the value of an id attribute from a substring of HTML code.
44
46
  const getIdentifiers = code => {
45
47
  let tagName = '';
@@ -47,7 +49,7 @@ const getIdentifiers = code => {
47
49
  // If the substring includes the start tag of an element:
48
50
  if (code && typeof code === 'string' && code.length && /<\s*[a-zA-Z]/.test(code)) {
49
51
  // Get the first start tag in the substring.
50
- const startTag = code.replace(/^.*?<(?=[a-zA-Z])/s, '').replace(/>.*$/s, '').trim();
52
+ const startTag = code.replace(/^.*?<(?=[a-zA-Z])/s, '').replace(/[^a-zA-Z].*$/gs, '').trim();
51
53
  // If it exists:
52
54
  if (startTag && startTag.length) {
53
55
  // Get its tag name, upper-cased.
@@ -57,6 +59,11 @@ const getIdentifiers = code => {
57
59
  if (idArray && idArray.length === 2) {
58
60
  id = idArray[1];
59
61
  }
62
+ // If the id value is invalid without character escaping:
63
+ if (isBadID(id)) {
64
+ // Remove it.
65
+ id = '';
66
+ }
60
67
  }
61
68
  }
62
69
  return [tagName, id];
@@ -207,7 +214,7 @@ const doHTMLCS = (result, standardResult, severity) => {
207
214
  what,
208
215
  ordinalSeverity: ['Warning', '', '', 'Error'].indexOf(severity),
209
216
  tagName: tagName.toUpperCase(),
210
- id: id.slice(1),
217
+ id: isBadID(id.slice(1)) ? '' : id.slice(1),
211
218
  location: {
212
219
  doc: 'dom',
213
220
  type: '',
@@ -317,7 +324,7 @@ const doWAVE = (result, standardResult, categoryName) => {
317
324
  if (finalTerm.includes('#')) {
318
325
  const finalArray = finalTerm.split('#');
319
326
  tagName = finalArray[0].replace(/:.*/, '');
320
- id = finalArray[1];
327
+ id = isBadID(finalArray[1]) ? '' : finalArray[1];
321
328
  }
322
329
  else {
323
330
  tagName = finalTerm.replace(/:.*/, '');
@@ -450,14 +457,16 @@ const convert = (toolName, data, result, standardResult) => {
450
457
  if (! tagName && finalRuleID.endsWith('_svg')) {
451
458
  tagName = 'SVG';
452
459
  }
453
- const excerpt = ruleResult.element && ruleResult.element.html || '';
460
+ const excerpt = ruleResult.element && ruleResult.element.html.replace(/\s+/g, ' ')
461
+ || '';
454
462
  if (! tagName && /^<[a-z]+[ >]/.test(excerpt)) {
455
- tagName = excerpt.slice(1).replace(/[ >]+/, '').toUpperCase();
463
+ tagName = excerpt.slice(1).replace(/[ >].+/, '').toUpperCase();
456
464
  }
457
465
  const idDraft = excerpt && excerpt.replace(/^[^[>]+id="/, 'id=').replace(/".*$/, '');
458
- const id = idDraft && idDraft.length > 3 && idDraft.startsWith('id=')
466
+ const idFinal = idDraft && idDraft.length > 3 && idDraft.startsWith('id=')
459
467
  ? idDraft.slice(3)
460
468
  : '';
469
+ const id = idFinal === '' || isBadID(idFinal) ? '' : idFinal;
461
470
  const instance = {
462
471
  ruleID: finalRuleID,
463
472
  what,
@@ -513,7 +522,7 @@ const convert = (toolName, data, result, standardResult) => {
513
522
  what,
514
523
  ordinalSeverity: 0,
515
524
  tagName,
516
- id,
525
+ id: isBadID(id) ? '' : id,
517
526
  location: {
518
527
  doc: 'dom',
519
528
  type: 'box',
@@ -567,7 +576,6 @@ const convert = (toolName, data, result, standardResult) => {
567
576
  if (result.rawPage) {
568
577
  doNuVal(result, standardResult, 'rawPage');
569
578
  }
570
- const {instances} = standardResult;
571
579
  }
572
580
  // qualWeb
573
581
  else if (