Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,38 @@ describe('main', () => {
// TODO: Add proper unit tests for the main module
expect(true).toBe(true)
})

describe('CWE ID normalization', () => {
const codeQlCweTagPrefix = 'external/cwe/cwe-'

function normalizeCweId(tag: string): string {
const cweId = tag.replace(codeQlCweTagPrefix, '')
const normalizedId = String(parseInt(cweId, 10))
return normalizedId
}

it('should handle CWE IDs with leading zeros', () => {
// Test that cwe-099 maps to 99
const normalizedId = normalizeCweId('external/cwe/cwe-099')
expect(normalizedId).toBe('99')
})

it('should handle CWE IDs without leading zeros', () => {
// Test that cwe-89 maps to 89
const normalizedId = normalizeCweId('external/cwe/cwe-89')
expect(normalizedId).toBe('89')
})

it('should handle CWE IDs with multiple leading zeros', () => {
// Test that cwe-020 maps to 20
const normalizedId = normalizeCweId('external/cwe/cwe-020')
expect(normalizedId).toBe('20')
})

it('should return NaN for non-numeric CWE IDs', () => {
// Test that invalid CWE IDs return NaN
const normalizedId = normalizeCweId('external/cwe/cwe-abc')
expect(normalizedId).toBe('NaN')
})
})
Comment thread
felickz marked this conversation as resolved.
})
10 changes: 8 additions & 2 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,15 @@ JSONPath({
for (const tag of tags) {
if (tag.startsWith(codeQlCweTagPrefix)) {
const cweId = tag.replace(codeQlCweTagPrefix, '')
if (cweIds.includes(cweId)) {
// Normalize CWE ID by converting to integer to remove leading zeros
const normalizedCweId = String(parseInt(cweId, 10))
// Skip if the CWE ID is not a valid number
if (normalizedCweId === 'NaN') {
continue
}
Comment thread
felickz marked this conversation as resolved.
Outdated
if (cweIds.includes(normalizedCweId)) {
tags.push(securityStandardTag)
tags.push(...cweCategories[cweId])
tags.push(...cweCategories[normalizedCweId])
return
}
}
Expand Down

Large diffs are not rendered by default.

Loading