Skip to content

Commit 2de8eaf

Browse files
authored
Merge pull request #32 from derkoe/fix/xml-encoding
fix: encoding of XML chars in tags
2 parents 0a1487e + 644d3e5 commit 2de8eaf

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

cyclonedx.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Affects struct {
4949
}
5050

5151
type AttachedText struct {
52-
Content string `json:"content" xml:",innerxml"`
52+
Content string `json:"content" xml:",chardata"`
5353
ContentType string `json:"contentType,omitempty" xml:"content-type,attr,omitempty"`
5454
Encoding string `json:"encoding,omitempty" xml:"encoding,attr,omitempty"`
5555
}
@@ -205,7 +205,7 @@ type Credits struct {
205205

206206
type DataClassification struct {
207207
Flow DataFlow `json:"flow" xml:"flow,attr"`
208-
Classification string `json:"classification" xml:",innerxml"`
208+
Classification string `json:"classification" xml:",chardata"`
209209
}
210210

211211
type DataFlow string
@@ -308,7 +308,7 @@ const (
308308

309309
type Hash struct {
310310
Algorithm HashAlgorithm `json:"alg" xml:"alg,attr"`
311-
Value string `json:"content" xml:",innerxml"`
311+
Value string `json:"content" xml:",chardata"`
312312
}
313313

314314
type HashAlgorithm string
@@ -517,7 +517,7 @@ type Pedigree struct {
517517

518518
type Property struct {
519519
Name string `json:"name" xml:"name,attr"`
520-
Value string `json:"value" xml:",innerxml"`
520+
Value string `json:"value" xml:",chardata"`
521521
}
522522

523523
type ReleaseNotes struct {

encode_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ func TestXmlBOMEncoder_SetPretty(t *testing.T) {
7373
Name: "authorName",
7474
},
7575
},
76+
Properties: &[]Property{
77+
{
78+
Name: "XML",
79+
Value: "<xml>in here</xml>",
80+
},
81+
{
82+
Name: "Specials",
83+
Value: "Special chars: < & > \"",
84+
},
85+
},
7686
}
7787

7888
require.NoError(t, encoder.Encode(bom))
@@ -85,6 +95,10 @@ func TestXmlBOMEncoder_SetPretty(t *testing.T) {
8595
<name>authorName</name>
8696
</author>
8797
</authors>
98+
<properties>
99+
<property name="XML">&lt;xml&gt;in here&lt;/xml&gt;</property>
100+
<property name="Specials">Special chars: &lt; &amp; &gt; &#34;</property>
101+
</properties>
88102
</metadata>
89103
</bom>`, buf.String())
90104
}

0 commit comments

Comments
 (0)