Skip to content

Commit e4a2951

Browse files
authored
Fix lua error in toChar and toUnicodeChar (#3310)
1 parent 0edfce0 commit e4a2951

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lua/entities/gmod_wire_expression2/core/string.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ local utf8_byte = utf8.codepoint
120120
__e2setcost(1)
121121

122122
e2function string toChar(number n)
123-
if n < 0 or n > 255 then return self:throw("Invalid argument (" .. n .. ") (must be between 0 and 255)", "") end
123+
if n ~= n or n < 0 or n > 255 then return self:throw("Invalid argument (" .. n .. ") (must not be NaN and be between 0 and 255)", "") end
124124
return string_char(n)
125125
end
126126

@@ -139,7 +139,7 @@ local math_floor = math.floor
139139
e2function string toUnicodeChar(number byte)
140140
-- upper limit used to be 2097152, new limit acquired using pcall and a for loop
141141
-- above this limit, the function causes a lua error
142-
if byte < 1 or byte > 1114112 then return self:throw("Invalid argument (" .. byte .. ") (must be between 1 and 1,114,112)", "") end
142+
if byte ~= byte or byte < 1 or byte > 1114112 then return self:throw("Invalid argument (" .. byte .. ") (must not be NaN and be between 1 and 1,114,112)", "") end
143143
return utf8_char(byte)
144144
end
145145

0 commit comments

Comments
 (0)