From 95d335c6566f7da0d358f5ca58a9cd7bef4f672c Mon Sep 17 00:00:00 2001 From: raskad <32105367+raskad@users.noreply.github.com> Date: Tue, 10 Aug 2021 03:16:03 +0200 Subject: [PATCH] Change StringGetOwnProperty to use String::from_utf16_lossy --- boa/src/builtins/string/tests.rs | 2 +- boa/src/object/internal_methods.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/boa/src/builtins/string/tests.rs b/boa/src/builtins/string/tests.rs index fbd0c2a13c4..5f00cd1a20f 100644 --- a/boa/src/builtins/string/tests.rs +++ b/boa/src/builtins/string/tests.rs @@ -1132,7 +1132,7 @@ fn string_get_property() { assert_eq!(forward(&mut context, "'abc'[2]"), "\"c\""); assert_eq!(forward(&mut context, "'abc'[3]"), "undefined"); assert_eq!(forward(&mut context, "'abc'['foo']"), "undefined"); - assert_eq!(forward(&mut context, "'😀'[0]"), "\"\\ud83d\""); + assert_eq!(forward(&mut context, "'😀'[0]"), "\"�\""); } #[test] diff --git a/boa/src/object/internal_methods.rs b/boa/src/object/internal_methods.rs index 8d5314ea49e..72b358abf6d 100644 --- a/boa/src/object/internal_methods.rs +++ b/boa/src/object/internal_methods.rs @@ -620,10 +620,10 @@ impl GcObject { return None; } - let result_str = string.encode_utf16().nth(pos).map(|utf16_val| { - char::from_u32(u32::from(utf16_val)) - .map_or_else(|| Value::from(format!("\\u{:x}", utf16_val)), Value::from) - })?; + let result_str = string + .encode_utf16() + .nth(pos) + .map(|utf16_val| Value::from(String::from_utf16_lossy(&[utf16_val])))?; let desc = PropertyDescriptor::builder() .value(result_str)