Skip to content

Commit

Permalink
Fix regex detection. Fixes micro#1663 (micro#1696)
Browse files Browse the repository at this point in the history
  • Loading branch information
domwong committed Jun 12, 2020
1 parent 0ce132e commit 0327f30
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/router/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *registryRouter) store(services []*registry.Service) {
for _, p := range ep.Endpoint.Path {
var pcreok bool

if p[0] == '^' && p[len(p)-1] != '$' {
if p[0] == '^' && p[len(p)-1] == '$' {
pcrereg, err := regexp.CompilePOSIX(p)
if err == nil {
cep.pcreregs = append(cep.pcreregs, pcrereg)
Expand Down
34 changes: 34 additions & 0 deletions api/router/registry/registry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package registry

import (
"testing"

"github.com/micro/go-micro/v2/registry"
"github.com/stretchr/testify/assert"
)

func TestStoreRegex(t *testing.T) {
router := newRouter()
router.store([]*registry.Service{
{
Name: "Foobar",
Version: "latest",
Endpoints: []*registry.Endpoint{
{
Name: "foo",
Metadata: map[string]string{
"endpoint": "FooEndpoint",
"description": "Some description",
"method": "POST",
"path": "^/foo/$",
"handler": "rpc",
},
},
},
Metadata: map[string]string{},
},
},
)

assert.Len(t, router.ceps["Foobar.foo"].pcreregs, 1)
}

0 comments on commit 0327f30

Please sign in to comment.