Skip to content

Commit

Permalink
Fix yet another place, that didn't handle multibyte characters correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
stirante committed Jul 12, 2023
1 parent dcde1aa commit 38b309e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions jsonte/custom_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func ProcessMCFunction(input string, scope types.JsonObject) (string, error) {

// ProcessString processes a string replacing all the jsonte expressions with their values
func ProcessString(input string, scope types.JsonObject, startToken, endToken string) (string, error) {
runes := []rune(input)
templateMatches, err := FindTemplateMatches(input, startToken, endToken)
if err != nil {
return "", burrito.PassError(err)
Expand All @@ -49,7 +50,7 @@ func ProcessString(input string, scope types.JsonObject, startToken, endToken st
lastMatchEnd := 0
for _, match := range templateMatches {
if match.Start > lastMatchEnd {
sb.WriteString(input[lastMatchEnd:match.Start])
sb.WriteString(string(runes[lastMatchEnd:match.Start]))
}
result, err := Eval(match.Match, globalScope, "#")
if err != nil {
Expand All @@ -65,7 +66,6 @@ func ProcessString(input string, scope types.JsonObject, startToken, endToken st
return "", burrito.WrappedErrorf("The expression '%s' evaluated to an action.", match.EscapedMatch)
}
}
runes := []rune(input)
if lastMatchEnd < len(runes) {
sb.WriteString(string(runes[lastMatchEnd:]))
}
Expand Down
6 changes: 4 additions & 2 deletions test/mcfunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ func TestMCFunctionNormalComment(t *testing.T) {
}

func TestMCFunctionEmoji(t *testing.T) {
f := `#{'emoji:🤣'}`
expected := `emoji:🤣`
f := `# 🔥
#{'emoji:🤣'}`
expected := `# 🔥
emoji:🤣`
assertMCFunction(t, f, expected)
}

0 comments on commit 38b309e

Please sign in to comment.