Skip to content

Commit 3693fef

Browse files
committed
bug fixed #1
1 parent a8364c6 commit 3693fef

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

strparam.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (s *PatternSchema) Lookup(in string) (bool, Params) {
112112
var offset int
113113

114114
for num, t := range s.Tokens {
115+
if len(in) < offset || len(in) < offset+t.Len {
116+
return false, nil
117+
}
118+
115119
switch t.Mode {
116120
case BEGINLINE:
117121
case ENDLINE:

strparam_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestParse(t *testing.T) {
2222
{"simple1", "foo{p1}bar", "foo123bar", Params{{"p1", "123"}}, true, false},
2323
{"utf8pattern", "foo{p1}日本語{p2}baz", "fooAAA日本語BBBbaz", Params{{"p1", "AAA"}, {"p2", "BBB"}}, true, false},
2424
{"utf8param", "foo{p1}bar{p2}baz", "foo日本語barСЫРbaz", Params{{"p1", "日本語"}, {"p2", "СЫР"}}, true, false},
25+
{"issues#1", "#snippet-{boundary}", "foobar", nil, false, false},
26+
{"issues#1", "verylongpattern-{p1}", "smallinput", nil, false, false},
2527
}
2628
for _, tt := range tests {
2729
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)