Skip to content

Commit

Permalink
Fix text conversion preventing command execution
Browse files Browse the repository at this point in the history
Converting / to ^s resulted in /commands not being parsed as commands.
Now the first slash is kept as-is and MST packets work for commands.
  • Loading branch information
Cykyrios committed Aug 3, 2024
1 parent da7bd7d commit 11343d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/test/unit/test_lfs_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ func test_unicode_to_lfs() -> void:
assert_eq(LFSText.unicode_to_lfs_string("ě ш マ"), "^Eì ^Cø ^JÏ")
assert_eq(LFSText.unicode_to_lfs_string("^72^45 ^7B2^4マ ^1Ayoub"), "^72^45 ^7B2^4^JÏ ^1Ayoub")
assert_eq(LFSText.unicode_to_lfs_string("^405 「^7マァ^4」 ^7TJ"), "^405 ^J¢^7ϧ^4£ ^7TJ")
assert_eq(LFSText.unicode_to_lfs_string("/command test"), "/command test")
assert_eq(LFSText.unicode_to_lfs_string("/command with a /slash"), "/command with a ^sslash")
8 changes: 6 additions & 2 deletions src/text_encoding/lfs_text.gd
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,12 @@ static func _remove_inner_zeros(buffer: PackedByteArray) -> PackedByteArray:
static func _translate_specials(text: String) -> String:
var message := text
for i in SPECIAL_CHARACTERS.size():
message = message.replace(SPECIAL_CHARACTERS.values()[i] as String,
SPECIAL_CHARACTERS.keys()[i] as String)
message = message.replace(str(SPECIAL_CHARACTERS.values()[i]),
str(SPECIAL_CHARACTERS.keys()[i]))
# Keep "basic" slash (U+2F) at beginning of message so it can be interpreted
# as an LFS command instead of text. This should not affect text representation otherwise.
if message.begins_with(str(SPECIAL_CHARACTERS.keys()[SPECIAL_CHARACTERS.values().find("/")])):
message = "/" + message.substr(2)
return message


Expand Down

0 comments on commit 11343d5

Please sign in to comment.