1 Commits

Author SHA1 Message Date
590f19603e Make regex matching set INTEGER keys not string 2025-11-03 19:07:15 +01:00
2 changed files with 6 additions and 7 deletions

View File

@@ -599,8 +599,8 @@ func EvalRegex(L *lua.LState) int {
if len(matches) > 0 {
matchesTable := L.NewTable()
for i, match := range matches {
matchesTable.RawSetString(fmt.Sprintf("%d", i), lua.LString(match))
evalRegexLogger.Debug("Set table[%d] = %q", i, match)
matchesTable.RawSetInt(i+1, lua.LString(match))
evalRegexLogger.Debug("Set table[%d] = %q", i+1, match)
}
L.Push(matchesTable)
} else {

View File

@@ -1,7 +1,6 @@
package processor_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
@@ -30,8 +29,8 @@ func TestEvalRegex_CaptureGroupsReturned(t *testing.T) {
}
expected := []string{"test-42", "test", "42"}
for i, v := range expected {
val := tbl.RawGetString(fmt.Sprintf("%d", i))
assert.Equal(t, lua.LString(v), val, "Expected index %d to be %q", i, v)
val := tbl.RawGetInt(i + 1)
assert.Equal(t, lua.LString(v), val, "Expected index %d to be %q", i+1, v)
}
}
@@ -67,9 +66,9 @@ func TestEvalRegex_NoCaptureGroups(t *testing.T) {
if !ok {
t.Fatalf("Expected Lua table, got %T", out)
}
fullMatch := tbl.RawGetString("0")
fullMatch := tbl.RawGetInt(1)
assert.Equal(t, lua.LString("foo123"), fullMatch)
// There should be only the full match (index 0)
// There should be only the full match (index 1)
count := 0
tbl.ForEach(func(k, v lua.LValue) {
count++