From f1bc857f66fdc7060ef3c67135fde3075029cc72 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Mon, 12 Apr 2021 17:36:15 +0100 Subject: [PATCH] Lifecycle: Accept empty tag in XML documents (#12039) Follow S3 to accept an empty filter tag inside an XML document. needs to be specified but it doesn't have to contain any other XML tags inside it. --- pkg/bucket/lifecycle/filter.go | 6 ++++-- pkg/bucket/lifecycle/lifecycle_test.go | 8 +++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pkg/bucket/lifecycle/filter.go b/pkg/bucket/lifecycle/filter.go index fe1d1f661..c69d27c26 100644 --- a/pkg/bucket/lifecycle/filter.go +++ b/pkg/bucket/lifecycle/filter.go @@ -28,6 +28,7 @@ var ( // Filter - a filter for a lifecycle configuration Rule. type Filter struct { XMLName xml.Name `xml:"Filter"` + set bool Prefix Prefix @@ -68,6 +69,7 @@ func (f Filter) MarshalXML(e *xml.Encoder, start xml.StartElement) error { // UnmarshalXML - decodes XML data. func (f *Filter) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) { + f.set = true for { // Read tokens from the XML document in a stream. t, err := d.Token() @@ -111,12 +113,12 @@ func (f *Filter) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error // IsEmpty returns true if Filter is not specified in the XML func (f Filter) IsEmpty() bool { - return !f.Prefix.set && !f.andSet && !f.tagSet + return !f.set } // Validate - validates the filter element func (f Filter) Validate() error { - if !f.Prefix.set && !f.andSet && !f.tagSet { + if f.IsEmpty() { return errXMLNotWellFormed } // A Filter must have exactly one of Prefix, Tag, or And specified. diff --git a/pkg/bucket/lifecycle/lifecycle_test.go b/pkg/bucket/lifecycle/lifecycle_test.go index b297c40be..60bed4834 100644 --- a/pkg/bucket/lifecycle/lifecycle_test.go +++ b/pkg/bucket/lifecycle/lifecycle_test.go @@ -86,12 +86,18 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) { expectedParsingErr: nil, expectedValidationErr: errXMLNotWellFormed, }, - // Legitimate lifecycle + // Lifecycle with the deprecated Prefix tag { inputConfig: `ruleEnabled1`, expectedParsingErr: nil, expectedValidationErr: nil, }, + // Lifecycle with empty Filter tag + { + inputConfig: `ruleEnabled1`, + expectedParsingErr: nil, + expectedValidationErr: nil, + }, } for i, tc := range testCases {