Skip to content

Commit a7c7c97

Browse files
authored
fix: encode quotation mark in URL (#724)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 8fe2b4a commit a7c7c97

13 files changed

+21
-12
lines changed

cyclonedx/model/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,8 @@ class XsUri(serializable.helpers.BaseHelper):
689689

690690
__SPEC_REPLACEMENTS = (
691691
(' ', '%20'),
692+
('"', '%22'),
693+
("'", '%27'),
692694
('[', '%5B'),
693695
(']', '%5D'),
694696
('<', '%3C'),

tests/_data/models.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1213,7 +1213,14 @@ def get_bom_for_issue_497_urls() -> Bom:
12131213
ExternalReference(
12141214
type=ExternalReferenceType.OTHER,
12151215
comment='control characters',
1216-
url=XsUri('https://acme.org/?foo=sp ace&bar[23]=42&lt=1<2&gt=3>2&cb={lol}')
1216+
url=XsUri('https://acme.org/?'
1217+
'foo=sp ace&'
1218+
'bar[23]=42&'
1219+
'lt=1<2&'
1220+
'gt=3>2&'
1221+
'cb={lol}&'
1222+
'quote="test"is\'test\''
1223+
)
12171224
),
12181225
ExternalReference(
12191226
type=ExternalReferenceType.OTHER,

tests/_data/snapshots/get_bom_for_issue_497_urls-1.1.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<comment>pre-encoded</comment>
1515
</reference>
1616
<reference type="other">
17-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
17+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
1818
<comment>control characters</comment>
1919
</reference>
2020
</externalReferences>

tests/_data/snapshots/get_bom_for_issue_497_urls-1.2.json.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"comment": "control characters",
1818
"type": "other",
19-
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D"
19+
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D&quote=%22test%22is%27test%27"
2020
}
2121
],
2222
"name": "dummy",

tests/_data/snapshots/get_bom_for_issue_497_urls-1.2.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<comment>pre-encoded</comment>
1818
</reference>
1919
<reference type="other">
20-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
20+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
2121
<comment>control characters</comment>
2222
</reference>
2323
</externalReferences>

tests/_data/snapshots/get_bom_for_issue_497_urls-1.3.json.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"comment": "control characters",
1818
"type": "other",
19-
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D"
19+
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D&quote=%22test%22is%27test%27"
2020
}
2121
],
2222
"name": "dummy",

tests/_data/snapshots/get_bom_for_issue_497_urls-1.3.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<comment>pre-encoded</comment>
1818
</reference>
1919
<reference type="other">
20-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
20+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
2121
<comment>control characters</comment>
2222
</reference>
2323
</externalReferences>

tests/_data/snapshots/get_bom_for_issue_497_urls-1.4.json.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"comment": "control characters",
1818
"type": "other",
19-
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D"
19+
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D&quote=%22test%22is%27test%27"
2020
}
2121
],
2222
"name": "dummy",

tests/_data/snapshots/get_bom_for_issue_497_urls-1.4.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<comment>pre-encoded</comment>
1717
</reference>
1818
<reference type="other">
19-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
19+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
2020
<comment>control characters</comment>
2121
</reference>
2222
</externalReferences>

tests/_data/snapshots/get_bom_for_issue_497_urls-1.5.json.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"comment": "control characters",
1818
"type": "other",
19-
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D"
19+
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D&quote=%22test%22is%27test%27"
2020
}
2121
],
2222
"name": "dummy",

tests/_data/snapshots/get_bom_for_issue_497_urls-1.5.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<comment>pre-encoded</comment>
1717
</reference>
1818
<reference type="other">
19-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
19+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
2020
<comment>control characters</comment>
2121
</reference>
2222
</externalReferences>

tests/_data/snapshots/get_bom_for_issue_497_urls-1.6.json.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
{
1717
"comment": "control characters",
1818
"type": "other",
19-
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D"
19+
"url": "https://acme.org/?foo=sp%20ace&bar%5B23%5D=42&lt=1%3C2&gt=3%3E2&cb=%7Blol%7D&quote=%22test%22is%27test%27"
2020
}
2121
],
2222
"name": "dummy",

tests/_data/snapshots/get_bom_for_issue_497_urls-1.6.xml.bin

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<comment>pre-encoded</comment>
1717
</reference>
1818
<reference type="other">
19-
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D</url>
19+
<url>https://acme.org/?foo=sp%20ace&amp;bar%5B23%5D=42&amp;lt=1%3C2&amp;gt=3%3E2&amp;cb=%7Blol%7D&amp;quote=%22test%22is%27test%27</url>
2020
<comment>control characters</comment>
2121
</reference>
2222
</externalReferences>

0 commit comments

Comments
 (0)