Skip to content

Commit

Permalink
fix: update deprecated build script (#28)
Browse files Browse the repository at this point in the history
* fix: update deprecated usage of fast-xml-parser
* docs: inform build command in readme
* fix: update deprecated test in CWE 4.13
  • Loading branch information
imnotkind committed Nov 15, 2023
1 parent 69b6d3a commit 809f314
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion __tests__/CweManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
})
})
})
9 changes: 5 additions & 4 deletions build/xmlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down Expand Up @@ -76,7 +76,7 @@ function convertXmlArchiveToJson({ cweArchiveFilepath }) {

const options = {
attributeNamePrefix: '@_',
attrNodeName: 'attr',
attributesGroupName: 'attr',
textNodeName: '#text',
ignoreAttributes: false,
ignoreNameSpace: false,
Expand All @@ -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
}

Expand Down

0 comments on commit 809f314

Please sign in to comment.