diff --git a/README.md b/README.md index f0eda2c..c57310e 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,8 @@ This CWE SDK has a build process that prepares the JSON data by downloading the This work is made possible thanks to scripts in `./build/` +To run it, execute `yarn run build` + # Contributing Please consult [CONTRIBUTING](./CONTRIBUTING.md) for guidelines on contributing to this project. diff --git a/__tests__/CweManager.test.js b/__tests__/CweManager.test.js index 2c4f35a..5e6ce2f 100644 --- a/__tests__/CweManager.test.js +++ b/__tests__/CweManager.test.js @@ -61,7 +61,7 @@ describe('Cwe Manager', () => { test('A CWE ID with memberships should return an array of ids', () => { const cweManager = new CweManager() const result = cweManager.getMemberships({ weaknessId: '778' }) - expect(result).toStrictEqual(['1009', '1036', '1210', '1308']) + expect(result).toStrictEqual(['1009', '1036', '1210', '1308', '1355', '1413']) }) }) }) diff --git a/build/xmlParser.js b/build/xmlParser.js index edaa745..9853ab3 100644 --- a/build/xmlParser.js +++ b/build/xmlParser.js @@ -3,7 +3,7 @@ /* eslint-disable security/detect-object-injection */ /* eslint-disable security/detect-non-literal-fs-filename */ const fs = require('fs') -const parser = require('fast-xml-parser') +const { XMLParser, XMLValidator } = require('fast-xml-parser') const debug = require('debug')('cwe-sdk:build') function createCweDictionary({ cweArchive }) { @@ -76,7 +76,7 @@ function convertXmlArchiveToJson({ cweArchiveFilepath }) { const options = { attributeNamePrefix: '@_', - attrNodeName: 'attr', + attributesGroupName: 'attr', textNodeName: '#text', ignoreAttributes: false, ignoreNameSpace: false, @@ -88,11 +88,12 @@ function convertXmlArchiveToJson({ cweArchiveFilepath }) { arrayMode: false } - if (parser.validate(xmlData) !== true) { + if (XMLValidator.validate(xmlData) !== true) { // @TODO xmlData is not valid } - const rawJsonCweArchive = parser.parse(xmlData, options) + const parser = new XMLParser(options) + const rawJsonCweArchive = parser.parse(xmlData) return rawJsonCweArchive }