From 04b7d41b1f563c3f7f0a1fb7fb40923e6fcb48c5 Mon Sep 17 00:00:00 2001 From: Jim Cummins Date: Sat, 20 Oct 2018 00:02:49 -0500 Subject: [PATCH] fix: Revert deal with config file charset (#525) (#583) This reverts commit c74eeb9e6b11c5740ca7b714579c5870334b3149. --- package.json | 1 - src/configLoader/getContent.js | 21 +-------------------- test/fixtures/invalid-charset.json | Bin 98 -> 0 bytes test/tests/configLoader.js | 2 -- 4 files changed, 1 insertion(+), 23 deletions(-) delete mode 100644 test/fixtures/invalid-charset.json diff --git a/package.json b/package.json index 1dc58858..3d2f0990 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,6 @@ "lodash": "4.17.11", "minimist": "1.2.0", "shelljs": "0.7.6", - "strip-bom": "3.0.0", "strip-json-comments": "2.0.1" }, "babel": { diff --git a/src/configLoader/getContent.js b/src/configLoader/getContent.js index 08918031..a24cabfe 100644 --- a/src/configLoader/getContent.js +++ b/src/configLoader/getContent.js @@ -2,8 +2,6 @@ import fs from 'fs'; import path from 'path'; import stripJSONComments from 'strip-json-comments'; -import isUTF8 from 'is-utf8'; -import stripBom from 'strip-bom'; import { getNormalizedConfig } from '../configLoader'; @@ -19,7 +17,7 @@ export default getConfigContent; function readConfigContent (configPath) { const parsedPath = path.parse(configPath) const isRcFile = parsedPath.ext !== '.js' && parsedPath.ext !== '.json'; - const jsonString = readConfigFileContent(configPath); + const jsonString = fs.readFileSync(configPath, 'utf-8'); const parse = isRcFile ? (contents) => JSON.parse(stripJSONComments(contents)) : (contents) => JSON.parse(contents); @@ -63,20 +61,3 @@ function getConfigContent (configPath, baseDirectory) { const content = readConfigContent(resolvedPath); return getNormalizedConfig(configBasename, content); }; - -/** - * Read proper content from config file. - * If the chartset of the config file is not utf-8, one error will be thrown. - * @param {String} configPath - * @return {String} - */ -function readConfigFileContent (configPath) { - - let rawBufContent = fs.readFileSync(configPath); - - if (!isUTF8(rawBufContent)) { - throw new Error(`The config file at "${configPath}" contains invalid charset, expect utf8`); - } - - return stripBom(rawBufContent.toString("utf8")); -} diff --git a/test/fixtures/invalid-charset.json b/test/fixtures/invalid-charset.json deleted file mode 100644 index 9c8d9573398c73b575867e84e6e1e30b97dff84e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 98 zcmezWubP32K>-St7>XJ48FCp?8I%~TfMQAvSzwVoAWH{DT?s=5Ln1>7TwNwmodQE9 ULmopJP&^07N&(7oG1M{u02NCQ1^@s6 diff --git a/test/tests/configLoader.js b/test/tests/configLoader.js index df8892b2..0a33e684 100644 --- a/test/tests/configLoader.js +++ b/test/tests/configLoader.js @@ -13,8 +13,6 @@ describe('configLoader', function () { .to.throw(/parsing json at/i); expect(() => getContent('invalid-json-rc', fixturesPath)) .to.throw(/parsing json at/i); - expect(() => getContent('invalid-charset.json', fixturesPath)) - .to.throw(/contains invalid charset/i); }); it('parses json files with comments', function () {