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

Don't allow invalid Unicode scalar values in char #3866

Merged
merged 2 commits into from
Mar 4, 2024

Conversation

daxpedda
Copy link
Collaborator

@daxpedda daxpedda commented Mar 2, 2024

This adds runtime checks for passing char from JS, which prevents invalid Unicode scalar values.

Fixes #2269.

self.global(
"
function _assertChar(c) {
if (typeof(c) === 'number' && (c >= 0x110000 || (c >= 0xD800 && c < 0xE000))) throw new Error(`expected a valid Unicode scalar value, found ${c}`);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I believe this should work, I also added a couple of tests for this as well.

@daxpedda daxpedda requested a review from Liamolucko March 2, 2024 14:07
Comment on lines 26 to 29
#[wasm_bindgen]
pub fn rust_js_option_identity(c: Option<char>) -> Option<char> {
js_option_identity(c)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem to be used.

@daxpedda
Copy link
Collaborator Author

daxpedda commented Mar 3, 2024

CI is currently broken because of rust-lang/rust#121932, which will be fixed tomorrow (hopefully) by rust-lang/rust#121933.

@daxpedda daxpedda merged commit 8e992dc into rustwasm:main Mar 4, 2024
25 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.

UB with impl FromWasmAbi for char when unpaired surrogate is given
2 participants