Skip to content

Commit bd63f63

Browse files
committed
Use ascii lowercase for module aliases
This matches with Luau 0.686 changes
1 parent c035c23 commit bd63f63

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/luau/require.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,14 @@ pub(super) fn create_require_function<R: Require + MaybeSend + 'static>(
570570
unsafe extern "C-unwind" fn to_lowercase(state: *mut ffi::lua_State) -> c_int {
571571
let s = ffi::luaL_checkstring(state, 1);
572572
let s = CStr::from_ptr(s);
573+
if !s.to_bytes().iter().any(|&c| c.is_ascii_uppercase()) {
574+
// If the string does not contain any uppercase ASCII letters, return it as is
575+
return 1;
576+
}
573577
callback_error_ext(state, ptr::null_mut(), true, |extra, _| {
574-
let s = s.to_string_lossy().to_lowercase();
578+
let s = (s.to_bytes().iter())
579+
.map(|&c| c.to_ascii_lowercase())
580+
.collect::<bstr::BString>();
575581
(*extra).raw_lua().push(s).map(|_| 1)
576582
})
577583
}

src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl Lua {
359359
return Err(Error::runtime("module name must begin with '@'"));
360360
}
361361
#[cfg(feature = "luau")]
362-
let modname = modname.to_lowercase();
362+
let modname = modname.to_ascii_lowercase();
363363
unsafe {
364364
self.exec_raw::<()>(value, |state| {
365365
ffi::luaL_getsubtable(state, ffi::LUA_REGISTRYINDEX, LOADED_MODULES_KEY);

0 commit comments

Comments
 (0)