Skip to content

Commit 717ebdd

Browse files
authored
Merge pull request #32 from eotsevych/issue/30-fix-json-deserialization-error
[Update] Flatten nested "target" arrays in Axe results
2 parents a377c8a + 15507ce commit 717ebdd

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/main/resources/js/axe.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ async function axeData(params) {
1010
results.device = device();
1111
results.browser = getBrowser();
1212
results.date = getFormattedDate();
13+
14+
flattenTargetArrays(results.violations);
15+
flattenTargetArrays(results.incomplete);
16+
flattenTargetArrays(results.inapplicable);
1317
return results;
1418
}
1519

@@ -100,4 +104,18 @@ function injectAxeScript(scriptURL) {
100104
script.addEventListener('error', e => reject(e.error));
101105
document.head.appendChild(script);
102106
});
107+
}
108+
109+
function flattenTargetArrays(resultsArray) {
110+
if (Array.isArray(resultsArray)) {
111+
resultsArray.forEach(result => {
112+
if (result.nodes && Array.isArray(result.nodes)) {
113+
result.nodes.forEach(node => {
114+
if (node.target && Array.isArray(node.target)) {
115+
node.target = node.target.flat();
116+
}
117+
});
118+
}
119+
});
120+
}
103121
}

0 commit comments

Comments
 (0)