Implemented repairing JSON objects containing special white space characters like non-breaking space
This commit is contained in:
parent
bf4e977427
commit
4875288cb7
|
@ -11,6 +11,8 @@ https://github.com/josdejong/jsoneditor
|
|||
- Implemented repairing JSON objects containing left and right single
|
||||
and double quotes (which you get when typing a JSON object in Word)
|
||||
in `text` and `code` mode.
|
||||
- Implemented repairing JSON objects containing special white space
|
||||
characters like non-breaking space.
|
||||
|
||||
|
||||
## 2017-09-16, version 5.9.6
|
||||
|
|
|
@ -163,6 +163,11 @@ exports.sanitize = function (jsString) {
|
|||
else if (c === '/' && next() === '/') {
|
||||
skipComment();
|
||||
}
|
||||
else if (c === '\u00A0' || (c >= '\u2000' && c <= '\u200A') || c === '\u202F' || c === '\u205F' || c === '\u3000') {
|
||||
// special white spaces (like non breaking space)
|
||||
chars.push(' ')
|
||||
i++
|
||||
}
|
||||
else if (c === quote) {
|
||||
parseString(quote);
|
||||
}
|
||||
|
|
|
@ -32,6 +32,11 @@ describe('util', function () {
|
|||
assert.equal(util.sanitize('"foo\\\'bar"'), '"foo\'bar"');
|
||||
});
|
||||
|
||||
it('should replace special white characters', function () {
|
||||
assert.equal(util.sanitize('{"a":\u00a0"foo\u00a0bar"}'), '{"a": "foo\u00a0bar"}');
|
||||
assert.equal(util.sanitize('{"a":\u2009"foo"}'), '{"a": "foo"}');
|
||||
});
|
||||
|
||||
it('should escape unescaped control characters', function () {
|
||||
assert.equal(util.sanitize('"hello\bworld"'), '"hello\\bworld"')
|
||||
assert.equal(util.sanitize('"hello\fworld"'), '"hello\\fworld"')
|
||||
|
@ -41,7 +46,7 @@ describe('util', function () {
|
|||
assert.equal(util.sanitize('{"value\n": "dc=hcm,dc=com"}'), '{"value\\n": "dc=hcm,dc=com"}')
|
||||
})
|
||||
|
||||
it.only('should replace left/right quotes', function () {
|
||||
it('should replace left/right quotes', function () {
|
||||
assert.equal(util.sanitize('\u2018foo\u2019'), '"foo"')
|
||||
assert.equal(util.sanitize('\u201Cfoo\u201D'), '"foo"')
|
||||
assert.equal(util.sanitize('\u0060foo\u00B4'), '"foo"')
|
||||
|
|
Loading…
Reference in New Issue