Skip to content

Commit 2da2d5a

Browse files
committed
make regexp non-greedy
1 parent 89d258d commit 2da2d5a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

builder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ const (
391391
paramPlaceHolder = "?"
392392
)
393393

394-
var searchHandle = regexp.MustCompile(`{{\S+}}`)
394+
var searchHandle = regexp.MustCompile(`{{\S+?}}`)
395395

396396
// NamedQuery is used for expressing complex query
397397
func NamedQuery(sql string, data map[string]interface{}) (string, []interface{}, error) {

builder/builder_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,18 @@ func TestNamedQuery(t *testing.T) {
525525
vals: []interface{}{1},
526526
err: nil,
527527
},
528+
{
529+
sql: `select {{foo}},{{bar}} from tb where age={{age}} and address in {{addr}}`,
530+
data: map[string]interface{}{
531+
"foo": "f1",
532+
"bar": "f2",
533+
"age": 10,
534+
"addr": []string{"beijing", "shanghai", "chengdu"},
535+
},
536+
cond: `select ?,? from tb where age=? and address in (?,?,?)`,
537+
vals: []interface{}{"f1", "f2", 10, "beijing", "shanghai", "chengdu"},
538+
err: nil,
539+
},
528540
}
529541
ass := assert.New(t)
530542
for _, tc := range testData {

0 commit comments

Comments
 (0)