0
0
Fork 0
mirror of https://github.com/denoland/rusty_v8.git synced 2025-01-13 09:33:02 -05:00

FastApiOneByteString is not always utf-8 (#1206)

This commit is contained in:
Divy Srivastava 2023-03-31 15:32:47 +05:30 committed by GitHub
parent a07c222ae3
commit fe7610aa4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 10 deletions

View file

@ -218,14 +218,9 @@ pub struct FastApiOneByteString {
impl FastApiOneByteString {
#[inline(always)]
pub fn as_str(&self) -> &str {
// SAFETY: The string is guaranteed to be valid UTF-8.
unsafe {
std::str::from_utf8_unchecked(std::slice::from_raw_parts(
self.data,
self.length as usize,
))
}
pub fn as_bytes(&self) -> &[u8] {
// SAFETY: The data is guaranteed to be valid for the length of the string.
unsafe { std::slice::from_raw_parts(self.data, self.length as usize) }
}
}

View file

@ -8915,8 +8915,8 @@ fn test_fast_calls_onebytestring() {
data: *const fast_api::FastApiOneByteString,
) -> u32 {
unsafe { WHO = "fast" };
let data = unsafe { &*data }.as_str();
assert_eq!("hello", data);
let data = unsafe { &*data }.as_bytes();
assert_eq!(b"hello", data);
data.len() as u32
}