Skip to content

Commit 809f314

Browse files
authored
fix: update deprecated build script (#28)
* fix: update deprecated usage of fast-xml-parser * docs: inform build command in readme * fix: update deprecated test in CWE 4.13
1 parent 69b6d3a commit 809f314

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ This CWE SDK has a build process that prepares the JSON data by downloading the
5252

5353
This work is made possible thanks to scripts in `./build/`
5454

55+
To run it, execute `yarn run build`
56+
5557
# Contributing
5658

5759
Please consult [CONTRIBUTING](./CONTRIBUTING.md) for guidelines on contributing to this project.

__tests__/CweManager.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ describe('Cwe Manager', () => {
6161
test('A CWE ID with memberships should return an array of ids', () => {
6262
const cweManager = new CweManager()
6363
const result = cweManager.getMemberships({ weaknessId: '778' })
64-
expect(result).toStrictEqual(['1009', '1036', '1210', '1308'])
64+
expect(result).toStrictEqual(['1009', '1036', '1210', '1308', '1355', '1413'])
6565
})
6666
})
6767
})

build/xmlParser.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable security/detect-object-injection */
44
/* eslint-disable security/detect-non-literal-fs-filename */
55
const fs = require('fs')
6-
const parser = require('fast-xml-parser')
6+
const { XMLParser, XMLValidator } = require('fast-xml-parser')
77
const debug = require('debug')('cwe-sdk:build')
88

99
function createCweDictionary({ cweArchive }) {
@@ -76,7 +76,7 @@ function convertXmlArchiveToJson({ cweArchiveFilepath }) {
7676

7777
const options = {
7878
attributeNamePrefix: '@_',
79-
attrNodeName: 'attr',
79+
attributesGroupName: 'attr',
8080
textNodeName: '#text',
8181
ignoreAttributes: false,
8282
ignoreNameSpace: false,
@@ -88,11 +88,12 @@ function convertXmlArchiveToJson({ cweArchiveFilepath }) {
8888
arrayMode: false
8989
}
9090

91-
if (parser.validate(xmlData) !== true) {
91+
if (XMLValidator.validate(xmlData) !== true) {
9292
// @TODO xmlData is not valid
9393
}
9494

95-
const rawJsonCweArchive = parser.parse(xmlData, options)
95+
const parser = new XMLParser(options)
96+
const rawJsonCweArchive = parser.parse(xmlData)
9697
return rawJsonCweArchive
9798
}
9899

0 commit comments

Comments
 (0)