From 335fa47ba1d90865b8e434478b161e658e9c8059 Mon Sep 17 00:00:00 2001 From: Vlad Barosan Date: Tue, 26 Jun 2018 16:33:56 -0700 Subject: [PATCH] Do BOM stripping for remote URL's --- ChangeLog.md | 6 ++++++ lib/util/utils.ts | 7 ++++--- package-lock.json | 2 +- package.json | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index dc8f28bf..8bbf6309 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,9 @@ +### 06/26/2018 0.4.51 +- Bug fix: Do BOM stripping for remote URL's [#266](https://github.com/Azure/oav/issues/266). + +### 06/20/2018 0.4.50 +- Replace sway dependency with yasway. + ### 06/19/2018 0.4.49 - Bug fix: Data is valid against more than one schema from `oneOf` [#248](https://github.com/Azure/oav/pull/248) The problem occurs when referenced model may also accept `null`. The fix is replacing `oneOf` with `anyOf`. diff --git a/lib/util/utils.ts b/lib/util/utils.ts index 36f87264..42c3788a 100644 --- a/lib/util/utils.ts +++ b/lib/util/utils.ts @@ -75,7 +75,7 @@ export async function parseJson(specPath: string): Promise { } else { // local filepath try { - const fileContent = stripBOM(fs.readFileSync(specPath, "utf8")) + const fileContent = fs.readFileSync(specPath, "utf8") const result = parseContent(specPath, fileContent) docCache[specPath] = Promise.resolve(result) return result @@ -101,10 +101,11 @@ export async function parseJson(specPath: string): Promise { */ export function parseContent(filePath: string, fileContent: string): Spec { let result = null + const sanitizedContent = stripBOM(fileContent) if (/.*\.json$/ig.test(filePath)) { - result = JSON.parse(fileContent) + result = JSON.parse(sanitizedContent) } else if (/.*\.ya?ml$/ig.test(filePath)) { - result = YAML.safeLoad(fileContent) + result = YAML.safeLoad(sanitizedContent) } else { const msg = `We currently support "*.json" and "*.yaml | *.yml" file formats for validating swaggers.\n` + diff --git a/package-lock.json b/package-lock.json index cb48b290..d60628e9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "0.4.50", + "version": "0.4.51", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index d92842e3..d2a7a900 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oav", - "version": "0.4.50", + "version": "0.4.51", "author": { "name": "Microsoft Corporation", "email": "azsdkteam@microsoft.com",