Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix string clamping for unicode characters #1724

Merged
merged 1 commit into from
Nov 17, 2024

Conversation

ccuser44
Copy link
Contributor

PoF:
image

PoF script:

MaxLen = function(message, length)
	local rawLength = string.len(message)
	local utf8Length = rawLength <= length * 6 and utf8.len(message)
	if rawLength > length and not (utf8Length and utf8Length <= length) then
		local clamped = string.sub(message, 1, utf8Length and utf8.offset(message, length + 1) - 1 or length)
		return `{not utf8.len(clamped) and string.sub(clamped, 1, select(2, utf8.len(clamped)) - 1) or clamped}...`
	else
		return message
	end
end;

local str = "Hêllö thëre ﷽ I äm â mürder!"

for i = utf8.len(str), 0, -1 do
	print(MaxLen(str, i))
end

@Dimenpsyonal Dimenpsyonal added the ✨ enhancement Enhancing or improving existing functionality label Nov 17, 2024
@Dimenpsyonal Dimenpsyonal merged commit abb33f9 into Epix-Incorporated:master Nov 17, 2024
2 of 3 checks passed
@ccuser44 ccuser44 deleted the patch-23 branch November 17, 2024 22:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
✨ enhancement Enhancing or improving existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants