Skip to content
This repository has been archived by the owner on Jul 6, 2022. It is now read-only.

Commit

Permalink
Fix allowedPattern issue (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
norshtein authored Dec 20, 2018
1 parent d1f8f39 commit f1607f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pkg/service/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ type StringPropertySchema struct {
MinLength *int `json:"minLength,omitempty"` // nolint: lll
MaxLength *int `json:"maxLength,omitempty"` // nolint: lll
AllowedValues []string `json:"enum,omitempty"`
AllowedPattern *regexp.Regexp `json:"pattern,omitempty"` // nolint: lll
AllowedPattern string `json:"pattern,omitempty"` // nolint: lll
CustomPropertyValidator CustomStringPropertyValidator `json:"-"`
DefaultValue string `json:"default,omitempty"` // nolint: lll
}
Expand Down Expand Up @@ -163,8 +163,9 @@ func (s StringPropertySchema) validate(
return NewValidationError(context, "field value is invalid")
}
}
if s.AllowedPattern != nil {
if !s.AllowedPattern.MatchString(val) {
if s.AllowedPattern != "" {
pattern := regexp.MustCompile(s.AllowedPattern)
if !pattern.MatchString(val) {
return NewValidationError(context, "field value is invalid")
}
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/service/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package service
import (
"encoding/json"
"fmt"
"regexp"
"testing"

"github.com/Azure/open-service-broker-azure/pkg/ptr"
Expand Down Expand Up @@ -199,7 +198,7 @@ func TestValidateStringProperty(t *testing.T) {
assert.Nil(t, err)

sps = StringPropertySchema{
AllowedPattern: regexp.MustCompile(`^\w{3}$`),
AllowedPattern: `^\w{3}$`,
}
// This should fail validation because the value does not match the regex
err = sps.validate(fieldName, "foobar")
Expand Down
6 changes: 2 additions & 4 deletions pkg/services/storage/plan_schemas.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package storage

import (
"regexp"

"github.com/Azure/open-service-broker-azure/pkg/ptr"
"github.com/Azure/open-service-broker-azure/pkg/schemas"
"github.com/Azure/open-service-broker-azure/pkg/service"
Expand Down Expand Up @@ -68,7 +66,7 @@ func generateProvisioningParamsSchema(serviceName string) service.InputParameter
Title: "Container Name",
Description: "The name of the container which will be created inside" +
"the blob stroage account",
AllowedPattern: regexp.MustCompile("^[a-z0-9]+(?:-[a-z0-9]+)*$"),
AllowedPattern: `^[a-z0-9]+(?:-[a-z0-9]+)*$`,
MinLength: ptr.ToInt(3),
MaxLength: ptr.ToInt(63),
}
Expand Down Expand Up @@ -122,7 +120,7 @@ func generateBlobContainerProvisioningParamsSchema() service.InputParametersSche
Title: "Container Name",
Description: "The name of the container which will be created inside" +
"the blob stroage account",
AllowedPattern: regexp.MustCompile("^[a-z0-9]+(?:-[a-z0-9]+)*$"),
AllowedPattern: `^[a-z0-9]+(?:-[a-z0-9]+)*$`,
MinLength: ptr.ToInt(3),
MaxLength: ptr.ToInt(63),
},
Expand Down

0 comments on commit f1607f6

Please sign in to comment.