Skip to content

Commit

Permalink
support for unicode chars and more test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
layerssss committed Nov 5, 2012
1 parent 8ad82ba commit 6807a10
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/json2yaml.js
Expand Up @@ -81,7 +81,7 @@
if (str.match(/^[\w]+$/)) {
return str;
} else {
return JSON.stringify(str);
return '"'+escape(str).replace(/%u/g,'\\u').replace(/%U/g,'\\U').replace(/%/g,'\\x')+'"';
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/basic.js
Expand Up @@ -17,3 +17,8 @@ test([ 'hello', { hello: 'world', hello2: [ 'hello', 'world' ] }, 'world' ]);
test([ 'hello', { hello: 'world', hello2: [ 'hello', 'world', { hello3: 'world3' } ] }, 'world' ]);
test({ hello: 1 });
test({ hello: true });
test({ hello: '你好, 世界!'});
test({ hello: '#你好, 世界!'});
test({ hello: '\\你好, 世界!'});
test({ hello: '"你好, 世界!'});
test({ hello: '%你好, 世界!'});

0 comments on commit 6807a10

Please sign in to comment.