testaro 45.0.2 → 45.0.3

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/procs/identify.js +13 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testaro",
3
- "version": "45.0.2",
3
+ "version": "45.0.3",
4
4
  "description": "Run 1000 web accessibility tests from 10 tools and get a standardized report",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/procs/identify.js CHANGED
@@ -83,6 +83,15 @@ const addIDs = async (locators, recipient) => {
83
83
  }
84
84
  }
85
85
  };
86
+ // Sanitizes a tag name.
87
+ const tagify = tagName => {
88
+ const lcTagName = tagName.toLowerCase();
89
+ const safeTagName = lcTagName.replace(/[^a-z0-9]/g, '');
90
+ if (safeTagName !== lcTagName) {
91
+ console.log(`ERROR: Tag name ${tagName} invalid`);
92
+ }
93
+ return safeTagName;
94
+ };
86
95
  // Returns the XPath and box ID of the element of a standard instance.
87
96
  exports.identify = async (instance, page) => {
88
97
  // If the instance does not yet have both boxID and pathID properties:
@@ -92,7 +101,8 @@ exports.identify = async (instance, page) => {
92
101
  boxID: '',
93
102
  pathID: ''
94
103
  };
95
- const {excerpt, id, location, tagName} = instance;
104
+ const {excerpt, id, location} = instance;
105
+ const tagName = tagify(instance.tagName);
96
106
  const {type, spec} = location;
97
107
  // If the instance specifies a CSS selector or XPath location:
98
108
  if (['selector', 'xpath'].includes(type)) {
@@ -156,14 +166,14 @@ exports.identify = async (instance, page) => {
156
166
  // If either ID remains undefined and the instance specifies a tag name:
157
167
  if (tagName && ! (elementID.boxID && elementID.pathID)) {
158
168
  // Get locators for elements with the tag name.
159
- let locators = page.locator(tagName.toLowerCase());
169
+ let locators = page.locator(tagName);
160
170
  // If there is exactly 1 of them:
161
171
  let locatorCount = await locators.count();
162
172
  if (locatorCount === 1) {
163
173
  // Add a box ID and a path ID to the result.
164
174
  await addIDs(locators, elementID);
165
175
  }
166
- // If either ID remains undefined an the instance also specifies an excerpt:
176
+ // If either ID remains undefined and the instance also specifies an excerpt:
167
177
  if (excerpt && ! (elementID.boxID && elementID.pathID)) {
168
178
  // Get the plain text parts of the excerpt, converting ... to an empty string.
169
179
  const minTagExcerpt = excerpt.replace(/<[^>]+>/g, '<>');