-
-
Notifications
You must be signed in to change notification settings - Fork 213
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
#1168@patch: Normalize whitespace in processing of DOMTokenList. #1169
#1168@patch: Normalize whitespace in processing of DOMTokenList. #1169
Conversation
private _getTokenList(): string[] { | ||
let attr = this._ownerElement.getAttribute(this._attributeName) ?? ''; | ||
attr = attr.replace(/^[\t\n\f\r ]+|[\t\n\f\r ]+$/g, ''); | ||
attr = attr.replace(/[\t\n\f\r ]+/g, ' '); |
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.
Hard to demonstrate as I’m typing on mobile, but String.prototype.split() accepts RegExp so this replace() and the next split() could both be reduced to one step.
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.
Thank you for the review. I have merged the two lines.
I learned a lot this time that String.prototype.split() accepts RegExp. Thank you again.
* String.prototype.split() accepts RegExp. * RegExp's g flag is ignored in split() so that g flag was removed.
eadf1bf
to
1f5a301
Compare
…o task/1168-normalize-whitespace
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.
Thank you for your contribution @takenspc! 🌟
Sorry for taking such a long time before reviewing this.
I have made some improvements to the logic in DOMTokenList.#getTokenList()
to improve its performance. I also merged the code and changed it to follow the new coding guidelines of using Symbol()
or #
for internal properties instead of "_" as prefix.
… after in DOMTokenList.
Normalize whitespace before splitting text into tokens.
Fixes #1168.