Skip to content

Commit 0edc1a3

Browse files
changed matchString to matchPattern and made the default to anchor the
pattern at the beginning and end of lines
1 parent 633fdc1 commit 0edc1a3

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

images/router/haproxy/conf/haproxy-config.template

+3-3
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ backend be_edge_http_{{$cfgIdx}}
227227
balance leastconn
228228
{{ end }}
229229
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
230-
{{if (matchString "^[1-9][0-9]*(us|ms|s|m|h|d)?$" $value) }}
230+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
231231
timeout server {{$value}}
232232
{{ end }}
233233
{{ end }}
@@ -265,7 +265,7 @@ backend be_tcp_{{$cfgIdx}}
265265
balance {{ env "ROUTER_TCP_BALANCE_SCHEME" "source" }}
266266
{{ end }}
267267
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
268-
{{if (matchString "^[1-9][0-9]*(us|ms|s|m|h|d)?$" $value) }}
268+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
269269
timeout server {{$value}}
270270
{{ end }}
271271
{{ end }}
@@ -293,7 +293,7 @@ backend be_secure_{{$cfgIdx}}
293293
balance leastconn
294294
{{ end }}
295295
{{ with $value := index $cfg.Annotations "router.openshift.io/haproxy.timeout"}}
296-
{{if (matchString "^[1-9][0-9]*(us|ms|s|m|h|d)?$" $value) }}
296+
{{if (matchPattern "[1-9][0-9]*(us|ms|s|m|h|d)?" $value) }}
297297
timeout server {{$value}}
298298
{{ end }}
299299
{{ end }}

pkg/router/template/plugin.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func NewTemplatePlugin(cfg TemplatePluginConfig) (*TemplatePlugin, error) {
9999
globalFuncs := template.FuncMap{
100100
"endpointsForAlias": endpointsForAlias,
101101
"env": env,
102-
"matchString": matchString,
102+
"matchPattern": matchPattern,
103103
"isInteger": isInteger,
104104
"matchValues": matchValues,
105105
}

pkg/router/template/router.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ func matchValues(s string, allowedValues ...string) bool {
187187
return false
188188
}
189189

190-
func matchString(pattern, s string) bool {
191-
glog.V(4).Infof("Matchstring called with %s and %s", pattern, s)
192-
status, err := regexp.MatchString(pattern, s)
190+
func matchPattern(pattern, s string) bool {
191+
glog.V(4).Infof("matchPattern called with %s and %s", pattern, s)
192+
status, err := regexp.MatchString("^"+pattern+"$", s)
193193
if err == nil {
194194
glog.V(4).Infof("Matchstring returning status: %v", status)
195195
return status
196196
}
197-
glog.Errorf("Error with regex pattern in call to matchString: %v", err)
197+
glog.Errorf("Error with regex pattern in call to matchPattern: %v", err)
198198
return false
199199
}
200200

0 commit comments

Comments
 (0)