File tree Expand file tree Collapse file tree 3 files changed +6
-7
lines changed
test/fixtures/dotnet-core-global-json Expand file tree Collapse file tree 3 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import 'source-map-support/register';
2
2
import * as fs from 'fs' ;
3
3
import * as path from 'path' ;
4
4
import { OpenSourceEcosystems } from '@snyk/error-catalog-nodejs-public' ;
5
+ import * as jsonc from 'jsonc-parser' ;
5
6
6
7
import {
7
8
DepType ,
@@ -323,13 +324,9 @@ function extractTargetSdkFromGlobalJson(
323
324
manifestFileContents : string ,
324
325
) : string | undefined {
325
326
try {
326
- // Remove /* */ comments from the JSON string (if any)
327
- // It's allowed: https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#comments-in-globaljson
328
- const jsonWithoutComments = manifestFileContents . replace (
329
- / \/ \* [ \s \S ] * ?\* \/ | \/ \/ .* $ / gm,
330
- '' ,
331
- ) ;
332
- const globalJsonAsObj = JSON . parse ( jsonWithoutComments ) ;
327
+ // Use a JSONC parser as that's the format of global.json, which accepts comments,
328
+ // see https://learn.microsoft.com/en-us/dotnet/core/tools/global-json#comments-in-globaljson
329
+ const globalJsonAsObj = jsonc . parse ( manifestFileContents ) ;
333
330
return globalJsonAsObj ?. sdk ?. version ;
334
331
} catch ( err : any ) {
335
332
throw new Error (
Original file line number Diff line number Diff line change 29
29
"homepage" : " https://github.com/snyk/dotnet-deps-parser#readme" ,
30
30
"dependencies" : {
31
31
"@snyk/error-catalog-nodejs-public" : " ^4.0.1" ,
32
+ "jsonc-parser" : " ^3.3.1" ,
32
33
"lodash" : " ^4.17.21" ,
33
34
"source-map-support" : " ^0.5.21" ,
34
35
"xml2js" : " 0.6.2"
Original file line number Diff line number Diff line change 1
1
{
2
2
// This is a comment.
3
3
"sdk" : {
4
+ "comment" : " This is a comment with a URL https://google.com" ,
4
5
"version" : " 7.0.100" /* This is comment 2*/
5
6
/* This is a
6
7
multiline comment.*/
You can’t perform that action at this time.
0 commit comments