Skip to content

Commit

Permalink
Both APIs fail when the key or value contain vertical tab. Fix that
Browse files Browse the repository at this point in the history
by adding escape sequencing for vertical tab

Add two unit tests to validate this scenario.
Fixes: ibmruntimes#31
  • Loading branch information
Ravali Yatham authored and Ravali Yatham committed Dec 20, 2021
1 parent 5809572 commit 2975b74
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/test-parse-verticaltab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const yj = require('../index');
const tap = require('tap');

//string with nested quotes
const str = '{"name":"Ila Gould","age":22,"gender":"female","nested":"\\u000bcheck"}';

yj.parseAsync(str, (error, obj) => {
if (!error){
tap.equal(str,JSON.stringify(obj));
yj.stringifyAsync(obj,(err,data) => {
if(!err){
tap.equal(data,str);
}
else
tap.fail(err);
})
}
else
tap.fail(error);
});
27 changes: 27 additions & 0 deletions test/test-stringify-verticaltab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const yj = require('../index');
const tap = require('tap');

//Object with nested quotes
const obj = {
name: 'Jacqueline Poole',
gender: 'female',
age: 40,
a:"\vb"
};

yj.stringifyAsync(obj, (err, str) => {
if (!err){
tap.equal(JSON.stringify(obj), str);
yj.parseAsync(str,(error,data) => {
if(!error){
tap.same(data,obj);
}
else
tap.fail(error);
})
}
else
tap.fail(err);
});
1 change: 1 addition & 0 deletions yieldable-stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ let normalize = (string, flagN) => {
'\n': '\\n',
'\f': '\\f',
'\r': '\\r',
'\v': '\\u000b',
'"': '\\"',
};
// Escape is implemented globally
Expand Down

0 comments on commit 2975b74

Please sign in to comment.