Skip to content

misc(proto): ensure all strings are well-formed - #15909

Merged
connorjclark merged 1 commit into
mainfrom
fix-utf
Apr 2, 2024
Merged

misc(proto): ensure all strings are well-formed#15909
connorjclark merged 1 commit into
mainfrom
fix-utf

Conversation

@connorjclark

@connorjclark connorjclark commented Apr 2, 2024

Copy link
Copy Markdown
Collaborator

fixes #15908

ref #14911

@connorjclark
connorjclark requested a review from a team as a code owner April 2, 2024 19:09
@connorjclark
connorjclark requested review from adamraine and removed request for a team April 2, 2024 19:09
}

removeStrings(reportJson);
iterateStrings(reportJson, (obj, key) => {

@paulirish paulirish Apr 2, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

rest of patch lgtm, but maybe extract this cb into a fn with a name? removeEmptyAndDropLoneSurrogates ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Aren't the comments inside sufficient and the code readable? detaching this anonymous fn from the utility function is more jumping around and doesn't help readabilty imo.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

well i suppose this entire file is also in the vein of "read it if you want to know what it does" so.. whatevs


// Sanitize lone surrogates.
// @ts-expect-error node 20
if (String.prototype.isWellFormed && !value.isWellFormed()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we throw an error if String.prototype.isWellFormed isn't available? Seems like we would want to fail loudly in that case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We absolutely do not want to throw an exception here, that would take down PSI for a very minor reason. Anyhow, WRS ships a Chrome that supports this and won't ever regress on that front.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gotcha, no error sounds good

@connorjclark
connorjclark merged commit 4fb9cea into main Apr 2, 2024
@connorjclark
connorjclark deleted the fix-utf branch April 2, 2024 20:12
obj.forEach(item => {
if (typeof item === 'object' || Array.isArray(item)) {
removeStrings(item);
iterateStrings(item, cb);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically this allows arrays with non-well-formed strings in them to pass through unchanged.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ah... same is true for empty strings sticking around. maybe it's fine ... 🪵 🤛

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lone surrogate character breaks PSI proto conversion

5 participants