Bug 1589738 - nsACString::as_str_unchecked should actually check in debug builds. r=nika

Today I reviewed wrong usage of this API.

It'd be good if it crashed in debug builds when misused.

Differential Revision: https://phabricator.services.mozilla.com/D49778

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-10-18 19:09:55 +00:00
parent 5accccfa94
commit f9f0e4b318

View File

@ -1086,8 +1086,13 @@ define_string_types! {
}
impl nsACString {
#[inline]
pub unsafe fn as_str_unchecked(&self) -> &str {
str::from_utf8_unchecked(self)
if cfg!(debug_assertions) {
str::from_utf8(self).expect("Should be utf-8")
} else {
str::from_utf8_unchecked(self)
}
}
}