Skip to content

Commit 0679533

Browse files
authored
fis: escape uri all (#1121)
Signed-off-by: Jan Kowalleck <[email protected]>
1 parent 3399a68 commit 0679533

23 files changed

+120
-115
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
<!-- add unreleased items here -->
88

9+
* Fixed
10+
* Imported URL sanitizer (via [#1121])
11+
12+
[#1121]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1121
13+
914
## 6.10.1 -- 2024-07-03
1015

1116
* Fixed

src/_helpers/uri.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ SPDX-License-Identifier: Apache-2.0
1717
Copyright (c) OWASP Foundation. All Rights Reserved.
1818
*/
1919

20-
const escapeMap: Readonly<Record<string, string>> = Object.freeze({
21-
' ': '%20',
22-
'[': '%5B',
23-
']': '%5D',
24-
'<': '%3C',
25-
'>': '%3E',
26-
'{': '%7B',
27-
'}': '%7D'
28-
})
20+
const _ESCAPES: Array<[RegExp, string]> = [
21+
[/ /g, '%20'],
22+
[/\[/g, '%5B'],
23+
[/]/g, '%5D'],
24+
[/</g, '%3C'],
25+
[/>/g, '%3E'],
26+
[/\{/g, '%7B'],
27+
[/}/g, '%7D']
28+
]
2929

3030
/**
3131
* Make a string valid to
@@ -43,7 +43,7 @@ export function escapeUri<T extends (string | undefined)> (value: T): T {
4343
if (value === undefined) {
4444
return value
4545
}
46-
for (const [s, r] of Object.entries(escapeMap)) {
46+
for (const [s, r] of _ESCAPES) {
4747
/* @ts-expect-error -- TS does not properly detect that value is to be forced as string, here */
4848
value = value.replace(s, r)
4949
}

tests/_data/models.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ module.exports.createComplexStructure = function () {
283283
['encode anyUri: https', 'https://example.org/p?k=v#f'],
284284
['encode anyUri: mailto', 'mailto:[email protected]'],
285285
['encode anyUri: relative path', '../foo/bar'],
286-
['encode anyUri: space', 'https://example.org/foo bar'],
287-
['encode anyUri: []', 'https://example.org/?bar[test]=baz'],
288-
['encode anyUri: <>', 'https://example.org/#<test>'],
289-
['encode anyUri: {}', 'https://example.org/#{test}'],
286+
['encode anyUri: space', 'https://example.org/foo bar bazz%20again+again'],
287+
['encode anyUri: []', 'https://example.org/?bar[test]=baz[again]'],
288+
['encode anyUri: <>', 'https://example.org/#<test><again>'],
289+
['encode anyUri: {}', 'https://example.org/#{test}{again}'],
290290
['encode anyUri: non-ASCII', 'https://example.org/édition'],
291-
['encode anyUri: partially encoded', 'https://example.org/?bar[test%5D=baz']
291+
['encode anyUri: partially encoded', 'https://example.org/?bar[test%5D=baz%5bagain]']
292292
].map(
293293
([desc, uri]) => new Models.ExternalReference(
294294
uri, Enums.ExternalReferenceType.Other, {

tests/_data/normalizeResults/json_sortedLists_spec1.2.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.3.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.4.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.5.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/json_sortedLists_spec1.6.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/xml_sortedLists_spec1.2.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/xml_sortedLists_spec1.3.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)