Skip to content

Commit

Permalink
Merge pull request #192 from dsame/fix/json-bom
Browse files Browse the repository at this point in the history
Add workaround to fix BOM-related error  during parsing global.json
  • Loading branch information
AlenaSviridenko committed May 4, 2021
2 parents 23fa2c1 + 34c59b7 commit 53d6483
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dist/index.js
Expand Up @@ -7829,7 +7829,9 @@ function run() {
core.debug('No version found, trying to find version from global.json');
const globalJsonPath = path.join(process.cwd(), 'global.json');
if (fs.existsSync(globalJsonPath)) {
const globalJson = JSON.parse(fs.readFileSync(globalJsonPath, { encoding: 'utf8' }));
const globalJson = JSON.parse(
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
fs.readFileSync(globalJsonPath, { encoding: 'utf8' }).trim());
if (globalJson.sdk && globalJson.sdk.version) {
version = globalJson.sdk.version;
}
Expand Down
3 changes: 2 additions & 1 deletion src/setup-dotnet.ts
Expand Up @@ -20,7 +20,8 @@ export async function run() {
const globalJsonPath = path.join(process.cwd(), 'global.json');
if (fs.existsSync(globalJsonPath)) {
const globalJson = JSON.parse(
fs.readFileSync(globalJsonPath, {encoding: 'utf8'})
// .trim() is necessary to strip BOM https://github.com/nodejs/node/issues/20649
fs.readFileSync(globalJsonPath, {encoding: 'utf8'}).trim()
);
if (globalJson.sdk && globalJson.sdk.version) {
version = globalJson.sdk.version;
Expand Down

0 comments on commit 53d6483

Please sign in to comment.