fix(utils): Add null check to parseCrossOriginStylesheet, closes #5074#5075
fix(utils): Add null check to parseCrossOriginStylesheet, closes #5074#5075dcbroad3 wants to merge 3 commits intodequelabs:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses axe-core issue #5074 by preventing parseCrossOriginStylesheet from attempting to fetch a stylesheet when the provided href/URL is nullish, avoiding erroneous network requests like "null".
Changes:
- Add a nullish check in
parseCrossOriginStylesheetto return early whenurl == null. - Add a unit test intended to cover the nullish-URL case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lib/core/utils/parse-crossorigin-stylesheet.js | Adds early return when the cross-origin stylesheet URL is nullish. |
| test/core/utils/parse-crossorigin-stylesheet.js | Adds coverage for the nullish-URL behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| isCrossOrigin | ||
| ) { | ||
| if (url == null) { | ||
| return Promise.resolve(); |
There was a problem hiding this comment.
I am following the pattern of the early return in parseSameOriginStylesheet if rules is falsy, but let me know if a different result should be returned (or if the function should do an early reject instead?)
| importedUrls, | ||
| isCrossOrigin | ||
| ) { | ||
| if (url == null) { |
There was a problem hiding this comment.
Actually thinking about this I wonder if we should reject the promise here instead of returning. If the cross origin stylesheet somehow has no href but has styles that are applying to the page, we should reject to signify we don't have the full styles. Let me ask my team about what they think.
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 howparseSameOriginStylesheetreturns early if a sheet includes no rules.Closes:
#5074