@cyclonedx/cyclonedx-library 1.3.2 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,6 +20,8 @@ Copyright (c) OWASP Foundation. All Rights Reserved.
20
20
  // eslint-disable-next-line @typescript-eslint/no-namespace
21
21
  export namespace XmlSchema {
22
22
 
23
+ const _anyUriSchemePattern = /^[a-z][a-z0-9+\-.]*$/i
24
+
23
25
  /**
24
26
  * @see isAnyURI
25
27
  */
@@ -28,13 +30,42 @@ export namespace XmlSchema {
28
30
  * Test whether format is XML::anyURI - best-effort.
29
31
  *
30
32
  * @see {@link http://www.w3.org/TR/xmlschema-2/#anyURI}
31
- * @see {@link http://www.datypic.com/sc/xsd/t-xsd_anyURI.html}
33
+ * @see {@link https://www.w3.org/2011/04/XMLSchema/TypeLibrary-URI-RFC3986.xsd}
34
+ * @see {@link https://www.w3.org/2011/04/XMLSchema/TypeLibrary-IRI-RFC3987.xsd}
32
35
  */
33
36
  export function isAnyURI (value: AnyURI | any): value is AnyURI {
34
- return typeof value === 'string' &&
35
- value.length > 0 &&
36
- Array.from(value).filter(c => c === '#').length <= 1
37
- // TODO add more validation according to spec
37
+ if (typeof value !== 'string') {
38
+ // not a string
39
+ return false
40
+ }
41
+ if (value.length === 0) {
42
+ // empty string
43
+ return false
44
+ }
45
+
46
+ const fragmentPos = value.indexOf('#')
47
+ let beforeFragment: string
48
+ if (fragmentPos >= 0) {
49
+ if (value.includes('#', fragmentPos + 1)) {
50
+ // has a second fragment marker
51
+ return false
52
+ }
53
+ beforeFragment = value.slice(undefined, fragmentPos)
54
+ } else {
55
+ beforeFragment = value
56
+ }
57
+
58
+ const schemePos = beforeFragment.indexOf(':')
59
+ if (schemePos >= 0) {
60
+ if (!_anyUriSchemePattern.test(beforeFragment.slice(undefined, schemePos))) {
61
+ // invalid schema
62
+ return false
63
+ }
64
+ }
65
+
66
+ // @TODO add more validation according to spec
67
+
68
+ return true
38
69
  }
39
70
 
40
71
  }