mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
Fix relabel.Regexp zero value marshalling (#14517)
Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
parent
71c90c71d4
commit
d4f098ae80
|
@ -213,6 +213,10 @@ func (re Regexp) IsZero() bool {
|
|||
|
||||
// String returns the original string used to compile the regular expression.
|
||||
func (re Regexp) String() string {
|
||||
if re.Regexp == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
str := re.Regexp.String()
|
||||
// Trim the anchor `^(?:` prefix and `)$` suffix.
|
||||
return str[4 : len(str)-2]
|
||||
|
|
|
@ -900,3 +900,16 @@ action: replace
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegexp_ShouldMarshalAndUnmarshalZeroValue(t *testing.T) {
|
||||
var zero Regexp
|
||||
|
||||
marshalled, err := yaml.Marshal(&zero)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "null\n", string(marshalled))
|
||||
|
||||
var unmarshalled Regexp
|
||||
err = yaml.Unmarshal(marshalled, &unmarshalled)
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, unmarshalled.Regexp)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue