Skip to content

Commit f12ef32

Browse files
authored
fix(utils): Add null check to parseCrossOriginStylesheet, closes #5074 (#5075)
If a null href is passed to `parseCrossOriginStylesheet`, the function will currently convert that to the string "null" and attempt to load that href. This PR adds a null check so that the function instead returns early if a nullish href is passed, similar to how `parseSameOriginStylesheet` returns early if a sheet includes no rules. Closes: #5074
1 parent 7d9d696 commit f12ef32

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

lib/core/utils/parse-crossorigin-stylesheet.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function parseCrossOriginStylesheet(
2020
importedUrls,
2121
isCrossOrigin
2222
) {
23+
if (url === null || url === undefined) {
24+
return Promise.resolve();
25+
}
26+
2327
/**
2428
* Add `url` to `importedUrls`
2529
*/

test/core/utils/parse-crossorigin-stylesheet.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,35 @@ describe('axe.utils.parseCrossOriginStylesheet', () => {
8989
done();
9090
});
9191
});
92+
93+
it('returns empty results when url is nullish', function (done) {
94+
this.timeout(axe.constants.preload.timeout + 1000);
95+
96+
var importUrl = null;
97+
var options = {
98+
rootNode: document,
99+
shadowId: undefined,
100+
convertDataToStylesheet: convertDataToStylesheet,
101+
rootIndex: 1
102+
};
103+
var priority = [1, 0];
104+
var importedUrls = [];
105+
var isCrossOriginRequest = true;
106+
107+
axe.utils
108+
.parseCrossOriginStylesheet(
109+
importUrl,
110+
options,
111+
priority,
112+
importedUrls,
113+
isCrossOriginRequest
114+
)
115+
.then(function (data) {
116+
assert.isUndefined(data);
117+
done();
118+
})
119+
.catch(function (err) {
120+
done(err);
121+
});
122+
});
92123
});

0 commit comments

Comments
 (0)