Skip to content

Commit

Permalink
chore: add ASCII check before convert Latin1 into str
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyboyQCD committed Feb 8, 2025
1 parent 3e2b90e commit c9cf38f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions core/engine/src/builtins/date/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,13 @@ pub(super) fn parse_date(date: &JsString, hooks: &dyn HostHooks) -> Option<i64>
let owned_js_str = date.as_str();
let owned_string: String;
let date = match owned_js_str.variant() {
JsStrVariant::Latin1(s) =>
// SAFETY: Since all characters are ASCII we can safely convert this into str.
unsafe { str::from_utf8_unchecked(s) },
JsStrVariant::Latin1(s) => {
if !s.is_ascii() {
return None;
}
// SAFETY: Since all characters are ASCII we can safely convert this into str.
unsafe { str::from_utf8_unchecked(s) }
}
JsStrVariant::Utf16(s) => {
owned_string = String::from_utf16(s).ok()?;
if !owned_string.is_ascii() {
Expand Down

0 comments on commit c9cf38f

Please sign in to comment.