Skip to content
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

Tabs: Use CSS.escape for sanitizing selectors #2307

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

mgol
Copy link
Member

@mgol mgol commented Oct 25, 2024

The previous private _sanitizeSelector API was not correctly escaping backslashes and is now removed. The native API should always be correct.

@mgol mgol added this to the 1.14.1 milestone Oct 25, 2024
@mgol mgol requested a review from fnagel October 25, 2024 16:32
@mgol mgol self-assigned this Oct 25, 2024
Comment on lines -315 to -317
_sanitizeSelector: function( hash ) {
return hash ? hash.replace( /[!"$%&'()*+,.\/:;<=>?@\[\]\^`{|}~]/g, "\\$&" ) : "";
},
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fnagel It's internal only so I thought we can just remove it. Or should we be conservative & only deprecate in 1.14? I don't know how jQuery UI historically approached removing private widget methods.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there's at least one case of $.fn._focus getting renamed to $.fn.focus between 1.10.1 & 1.10.2: 1.10.1...1.10.2

Copy link
Member

@fnagel fnagel Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh that is in indeed a good question. Iirc Scott would not make a big thing of changing internal methods but I'm not really sure.

Why not just keep the $.fn._sanitizeSelector $.ui.tabs.prototype._sanitizeSelector until the next minor release but make it use CSS.escape?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just seen its not $.fn but $.ui.tabs so it's even more specific (as in Tabs widget only). Not sure if its worth keeping the old method around...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I'll keep it removed then. There's no universal way to sanitize the whole selector; the safe thing to do is to just escape the identifier part, especially when potentially coming from user input. Even if I changed the internal method to use CSS.escape, it would just handle the "# + id" case, which can be confusing and can still lead people to use it where it's not intended.

@mgol mgol force-pushed the tabs-sanitize-selector branch from d57df64 to 7f64617 Compare October 25, 2024 21:21
@mgol mgol force-pushed the tabs-sanitize-selector branch from 7f64617 to cd43cb6 Compare October 25, 2024 21:27
The previous private `_sanitizeSelector` API was not correctly escaping
backslashes and is now removed. The native API should always be correct.
@mgol mgol force-pushed the tabs-sanitize-selector branch from cd43cb6 to 3112528 Compare October 25, 2024 22:45
@mgol mgol removed the Needs review label Oct 26, 2024
@mgol mgol merged commit af8adca into jquery:main Oct 26, 2024
11 checks passed
@mgol mgol deleted the tabs-sanitize-selector branch October 26, 2024 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants