diff --git a/internal/staticsources/handler.go b/internal/staticsources/handler.go index a8ee24ab..80b18616 100644 --- a/internal/staticsources/handler.go +++ b/internal/staticsources/handler.go @@ -32,10 +32,8 @@ func emptyTimer() *time.Timer { } func resolveSource(s string, matches []string, query string) string { - if len(matches) > 1 { - for i, ma := range matches[1:] { - s = strings.ReplaceAll(s, "$G"+strconv.FormatInt(int64(i+1), 10), ma) - } + for i := len(matches) - 1; i >= 1; i-- { + s = strings.ReplaceAll(s, "$G"+strconv.FormatInt(int64(i), 10), matches[i]) } s = strings.ReplaceAll(s, "$MTX_QUERY", query) diff --git a/internal/staticsources/handler_test.go b/internal/staticsources/handler_test.go index 053ebcbc..3f606789 100644 --- a/internal/staticsources/handler_test.go +++ b/internal/staticsources/handler_test.go @@ -105,6 +105,13 @@ func TestResolveSource(t *testing.T) { query: "", expected: "udp+rtp://192.168.1.100:5000", }, + { + name: "multi digit group substitution", + source: "rtsp://example.com/$G10", + matches: []string{"full", "g1", "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9", "g10"}, + query: "", + expected: "rtsp://example.com/g10", + }, } { t.Run(ca.name, func(t *testing.T) { result := resolveSource(ca.source, ca.matches, ca.query)