Skip to content

Commit 8eacb16

Browse files
authored
Merge pull request #129 from everettraven/bugfix/marker-regex
(bugfix): analysis: markers: handle backticks for attribute values
2 parents cf6e504 + 49f333f commit 8eacb16

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

pkg/analysis/helpers/markers/analyzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func extractKnownMarkerIDAndExpressions(id string, marker string) (string, map[s
230230
return id, extractExpressions(strings.TrimPrefix(marker, id))
231231
}
232232

233-
var expressionRegex = regexp.MustCompile(`\w*=(?:'[^']*'|"(\\"|[^"])*"|[\w;\-"]+)`)
233+
var expressionRegex = regexp.MustCompile("\\w*=(?:'[^']*'|\"(\\\\\"|[^\"])*\"|[\\w;\\-\"]+|`[^`]*`)")
234234

235235
func extractExpressions(expressionStr string) map[string]string {
236236
expressionsMap := map[string]string{}

pkg/analysis/helpers/markers/analyzer_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ func TestExtractMarkerIdAndExpressions(t *testing.T) {
121121
"": "-10",
122122
},
123123
},
124+
{
125+
name: "registered marker with named expression using backtick ('`') for strings",
126+
marker: "kubebuilder:validation:XValidation:rule=`has(self.field)`,message=`must have field!`",
127+
expectedID: "kubebuilder:validation:XValidation",
128+
expectedExpressions: map[string]string{
129+
"rule": "`has(self.field)`",
130+
"message": "`must have field!`",
131+
},
132+
},
124133
}
125134

126135
for _, tc := range testcases {

0 commit comments

Comments
 (0)