我正在实施UTF-8的支持,我正面临一个问题。我想收到无效的UTF-8错误。好:
var utf8 = require('utf8');
try {
var result = utf8.decode(req.params.container);
console.log('a valid utf8 (from ', req.params.container , '): ', result);
self.bucket_name = req.params.container;
next();
} catch (e) {
console.log('Invalid UTF-8 (', req.params.container, '): ', e);
res.statusCode = 412;
res.end('Invalid UTF8 or contains NULL');
} finally {
;
}
然后它说这个unicode字符串无效:嘈音Ωऀ鐌鐌㜄鐊툏㜃蔈蔈㜅㜅㜅
但是有些python库说这个字符串是有效的unicode。所以我的问题有两个:(1)是有效的UTF-8,以及(2)我如何在node.js中确定字符串是否有效utf-8?