fix: make keyword_token safe by validating UTF-8 input

This commit is contained in:
ankit
2025-06-06 16:25:49 +05:30
parent c7ec4a6270
commit 4c3c72b666

View File

@@ -46,9 +46,8 @@ pub(crate) const MAX_KEYWORD_LEN: usize = 17;
/// Check if `word` is a keyword
pub fn keyword_token(word: &[u8]) -> Option<TokenType> {
KEYWORDS
.get(UncasedStr::new(unsafe { str::from_utf8_unchecked(word) }))
.copied()
let s = std::str::from_utf8(word).ok()?;
KEYWORDS.get(UncasedStr::new(s)).cloned()
}
pub(crate) fn is_identifier(name: &str) -> bool {