Skip to content

Commit

Permalink
config: when returning compiled regexps slice, make sure to return a …
Browse files Browse the repository at this point in the history
…copy as extra precaution
  • Loading branch information
DarkCaster committed Jan 6, 2025
1 parent 604d290 commit f0d811f
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/config_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func compileRegexArray(source []string, name string) ([]*regexp.Regexp, error) {

func interfaceToStringArray(source interface{}) []string {
sourceArray := source.([]interface{})
target := make([]string, len(sourceArray))
target := make([]string, len(sourceArray), cap(sourceArray))
for i, element := range sourceArray {
target[i] = element.(string)
}
Expand All @@ -117,7 +117,7 @@ func interfaceToStringArray(source interface{}) []string {

func interfaceTo2DStringArray(source interface{}) [][]string {
sourceArray := source.([]interface{})
target := make([][]string, len(sourceArray))
target := make([][]string, len(sourceArray), cap(sourceArray))
for i, element := range sourceArray {
target[i] = interfaceToStringArray(element)
}
Expand Down
2 changes: 1 addition & 1 deletion config/op_annotate_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (o *opAnnotateConfig) Regexp(key string) *regexp.Regexp {
}

func (o *opAnnotateConfig) RegexpArray(key string) []*regexp.Regexp {
return o.cfgValues[key].([]*regexp.Regexp)
return utils.NewSlice(o.cfgValues[key].([]*regexp.Regexp)...)
}

func (o *opAnnotateConfig) String(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion config/op_doc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (o *opDocConfig) Regexp(key string) *regexp.Regexp {
}

func (o *opDocConfig) RegexpArray(key string) []*regexp.Regexp {
return o.cfgValues[key].([]*regexp.Regexp)
return utils.NewSlice(o.cfgValues[key].([]*regexp.Regexp)...)
}

func (o *opDocConfig) String(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion config/op_implement_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (o *opImplementConfig) Regexp(key string) *regexp.Regexp {
}

func (o *opImplementConfig) RegexpArray(key string) []*regexp.Regexp {
return o.cfgValues[key].([]*regexp.Regexp)
return utils.NewSlice(o.cfgValues[key].([]*regexp.Regexp)...)
}

func (o *opImplementConfig) String(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion config/op_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (o *opReportConfig) Regexp(key string) *regexp.Regexp {
}

func (o *opReportConfig) RegexpArray(key string) []*regexp.Regexp {
return o.cfgValues[key].([]*regexp.Regexp)
return utils.NewSlice(o.cfgValues[key].([]*regexp.Regexp)...)
}

func (o *opReportConfig) String(key string) string {
Expand Down
2 changes: 1 addition & 1 deletion config/project_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (o *projectConfig) Regexp(key string) *regexp.Regexp {
}

func (o *projectConfig) RegexpArray(key string) []*regexp.Regexp {
return o.cfgValues[key].([]*regexp.Regexp)
return utils.NewSlice(o.cfgValues[key].([]*regexp.Regexp)...)
}

func (o *projectConfig) String(key string) string {
Expand Down

0 comments on commit f0d811f

Please sign in to comment.