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

#1168@patch: Normalize whitespace in processing of DOMTokenList. #1169

Merged

Conversation

takenspc
Copy link
Contributor

Normalize whitespace before splitting text into tokens.

Fixes #1168.

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, ' ');

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.

Copy link
Contributor Author

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.
@takenspc takenspc force-pushed the task/1168-normalize-whitespace branch from eadf1bf to 1f5a301 Compare November 28, 2023 12:18
capricorn86
capricorn86 previously approved these changes Jan 14, 2024
Copy link
Owner

@capricorn86 capricorn86 left a 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.

@capricorn86 capricorn86 merged commit ee4eb6f into capricorn86:master Jan 14, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Element.classList has empty string item when a class attribute contains multiple spaces
3 participants