mirror of
https://github.com/minio/minio.git
synced 2025-04-01 10:13:42 -04:00
Lifecycle: Accept empty <Filter> tag in XML documents (#12039)
Follow S3 to accept an empty filter tag inside an XML document. <Filter> needs to be specified but it doesn't have to contain any other XML tags inside it.
This commit is contained in:
parent
8ab111cfb6
commit
f1bc857f66
@ -28,6 +28,7 @@ var (
|
|||||||
// Filter - a filter for a lifecycle configuration Rule.
|
// Filter - a filter for a lifecycle configuration Rule.
|
||||||
type Filter struct {
|
type Filter struct {
|
||||||
XMLName xml.Name `xml:"Filter"`
|
XMLName xml.Name `xml:"Filter"`
|
||||||
|
set bool
|
||||||
|
|
||||||
Prefix Prefix
|
Prefix Prefix
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ func (f Filter) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|||||||
|
|
||||||
// UnmarshalXML - decodes XML data.
|
// UnmarshalXML - decodes XML data.
|
||||||
func (f *Filter) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
|
func (f *Filter) UnmarshalXML(d *xml.Decoder, start xml.StartElement) (err error) {
|
||||||
|
f.set = true
|
||||||
for {
|
for {
|
||||||
// Read tokens from the XML document in a stream.
|
// Read tokens from the XML document in a stream.
|
||||||
t, err := d.Token()
|
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
|
// IsEmpty returns true if Filter is not specified in the XML
|
||||||
func (f Filter) IsEmpty() bool {
|
func (f Filter) IsEmpty() bool {
|
||||||
return !f.Prefix.set && !f.andSet && !f.tagSet
|
return !f.set
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate - validates the filter element
|
// Validate - validates the filter element
|
||||||
func (f Filter) Validate() error {
|
func (f Filter) Validate() error {
|
||||||
if !f.Prefix.set && !f.andSet && !f.tagSet {
|
if f.IsEmpty() {
|
||||||
return errXMLNotWellFormed
|
return errXMLNotWellFormed
|
||||||
}
|
}
|
||||||
// A Filter must have exactly one of Prefix, Tag, or And specified.
|
// A Filter must have exactly one of Prefix, Tag, or And specified.
|
||||||
|
@ -86,12 +86,18 @@ func TestParseAndValidateLifecycleConfig(t *testing.T) {
|
|||||||
expectedParsingErr: nil,
|
expectedParsingErr: nil,
|
||||||
expectedValidationErr: errXMLNotWellFormed,
|
expectedValidationErr: errXMLNotWellFormed,
|
||||||
},
|
},
|
||||||
// Legitimate lifecycle
|
// Lifecycle with the deprecated Prefix tag
|
||||||
{
|
{
|
||||||
inputConfig: `<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><ID>rule</ID><Prefix /><Status>Enabled</Status><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>`,
|
inputConfig: `<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><ID>rule</ID><Prefix /><Status>Enabled</Status><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>`,
|
||||||
expectedParsingErr: nil,
|
expectedParsingErr: nil,
|
||||||
expectedValidationErr: nil,
|
expectedValidationErr: nil,
|
||||||
},
|
},
|
||||||
|
// Lifecycle with empty Filter tag
|
||||||
|
{
|
||||||
|
inputConfig: `<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><Rule><ID>rule</ID><Filter></Filter><Status>Enabled</Status><Expiration><Days>1</Days></Expiration></Rule></LifecycleConfiguration>`,
|
||||||
|
expectedParsingErr: nil,
|
||||||
|
expectedValidationErr: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, tc := range testCases {
|
for i, tc := range testCases {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user