-
Notifications
You must be signed in to change notification settings - Fork 5
fix: extra protection around tagName accessor #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/getTag.js
Outdated
// This can happen when a <form> element contains an <input> | ||
// with an id of `tagName`. In this case, the form element's | ||
// tagName property is a reference to the input element, not | ||
// a string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wuuuuuuut?
TIL
src/getTag.js
Outdated
@@ -6,6 +6,17 @@ | |||
*/ | |||
export function getTag( el, filter ) | |||
{ | |||
if (typeof el.tagName !== 'string') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe fall back to try nodeName
in this case, and if that's also non-string then all bets are off and return null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, validating it in the browser and it seems like nodeName is not effected by the tagName override (unless an input has an id of nodeName, in which case it is lol).
So the only place we'd fall down is if we had a form like:
<form>
<input id="tagName" />
<input id="nodeName" />
</form>
nodeName
is used by the isElement
checks so having that overridden would be much more painful. I don't think we've seen that yet 🤞
🎉 This PR is included in version 2.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Alert: https://cypressio.slack.com/archives/C0614M4DZV5/p1746718971129419
We have a test case in the cypress-services repo that specifically overrides a form element's
tagName
property using a nested<input id="tagName">
element. When the form is processed with unique-selector, unique-selector will throw as a result of this overridden property that references an element (rather than the expected string). This is causing a few alerts to come through (and knocking our Cypress reports into a "Processed with errors" state).So, added a little check to ignore tagName when it's not the expected type.
I looked at the other accessors in use here, and most everything else goes through a
getAttribute
call. I [don't think we can really be exhaustive here without going overboard, buttagName
overrides are something the App has run into as well, so we might as well work around it (and keep our own tests happy). If we notice other goofy things happening to elements, we can evaluate further protections.