Merge pull request #41 from jwetzell/fix/dtmf-create-rune-check

return error if DTMF create results in invalid characters
This commit is contained in:
Joel Wetzell
2026-01-17 18:40:53 -06:00
committed by GitHub

View File

@@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"context" "context"
"errors" "errors"
"regexp"
"text/template" "text/template"
"github.com/jwetzell/showbridge-go/internal/config" "github.com/jwetzell/showbridge-go/internal/config"
@@ -14,6 +15,7 @@ type SipResponseDTMFCreate struct {
PreWait int PreWait int
PostWait int PostWait int
Digits *template.Template Digits *template.Template
validDTMF *regexp.Regexp
} }
type SipDTMFResponse struct { type SipDTMFResponse struct {
@@ -33,6 +35,10 @@ func (scc *SipResponseDTMFCreate) Process(ctx context.Context, payload any) (any
digitsString := digitsBuffer.String() digitsString := digitsBuffer.String()
if !scc.validDTMF.MatchString(digitsString) {
return nil, errors.New("sip.response.dtmf.create result of digits template contains invalid characters")
}
return SipDTMFResponse{ return SipDTMFResponse{
PreWait: scc.PreWait, PreWait: scc.PreWait,
PostWait: scc.PostWait, PostWait: scc.PostWait,
@@ -91,7 +97,7 @@ func init() {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum)}, nil return &SipResponseDTMFCreate{config: config, Digits: digitsTemplate, PreWait: int(preWaitNum), PostWait: int(postWaitNum), validDTMF: regexp.MustCompile(`^[0-9*#A-Da-d]+$`)}, nil
}, },
}) })
} }