diff --git a/schema.go b/schema.go index eacfb45b..7f80dfd1 100644 --- a/schema.go +++ b/schema.go @@ -245,7 +245,7 @@ type NameIDPolicy struct { // Element returns an etree.Element representing the object in XML form. func (a *NameIDPolicy) Element() *etree.Element { el := etree.NewElement("samlp:NameIDPolicy") - if a.Format != nil { + if a.Format != nil && *a.Format != "" { el.CreateAttr("Format", *a.Format) } if a.SPNameQualifier != nil { diff --git a/schema_test.go b/schema_test.go index c1073f6c..a8a6ec23 100644 --- a/schema_test.go +++ b/schema_test.go @@ -32,3 +32,17 @@ func TestAttributeXMLRoundTrip(t *testing.T) { assert.NoError(t, err) assert.Equal(t, expected, actual) } + +func TestNameIDFormat(t *testing.T) { + var emptyString string + el := NameIDPolicy{ + Format: &emptyString, + } + doc := etree.NewDocument() + doc.SetRoot(el.Element()) + x, err := doc.WriteToBytes() + assert.NoError(t, err) + assert.Equal(t, + "", + string(x)) +}