diff --git a/src/__tests__/index.js b/src/__tests__/index.js index 0570ed1..79a5d78 100644 --- a/src/__tests__/index.js +++ b/src/__tests__/index.js @@ -112,6 +112,21 @@ describe('fix trailing characters', () => { }) }) + it('chars', () => { + const json = fs.readFileSync('./test/samples/trailingChar.json', 'utf-8') + const {data, changed} = jf(json) + expect(changed).toBeTruthy() + expect(data).toEqual([ + { + test1: '1', + test2: { + a: 'b', + c: {}, + }, + }, + ]) + }) + it('hex\'s "x"', () => { const json = fs.readFileSync('./test/samples/x.json', 'utf-8') const {data, changed} = jf(json) diff --git a/src/fixer.js b/src/fixer.js index e773f64..885a116 100644 --- a/src/fixer.js +++ b/src/fixer.js @@ -4,7 +4,9 @@ const {parse} = require('./json.pjs') const fixExtraChar = ({fixedData, verbose, targetLine}) => { if (verbose) psw(chalk.magenta('Extra character')) + if (fixedData[targetLine] === '') --targetLine const brokenLine = removeLinebreak(fixedData[targetLine]) + let fixedLine = brokenLine.trimEnd() fixedLine = fixedLine.substr(0, fixedLine.length - 1) fixedData[targetLine] = fixedLine diff --git a/test/samples/trailingChar.json b/test/samples/trailingChar.json new file mode 100644 index 0000000..6c9fdc1 --- /dev/null +++ b/test/samples/trailingChar.json @@ -0,0 +1,12 @@ +[ + { + "test1": "1", + "test2": { + "a": "b", + "c": { + + }, + + } + } +] \ No newline at end of file