Commit dc9d6e8a authored by Jérémy Lal's avatar Jérémy Lal

New upstream version 2.2.1

parent 9033acdb
......@@ -72,8 +72,13 @@ module.
## Compiling from source
$ git clone git://github.com/bnoordhuis/node-iconv.git
$ node-gyp configure build
$ npm install .
$ cd node-iconv
$ npm install
If you have a specific node.js source checkout that you want to build against,
replace the last command with:
$ npm install --nodedir=/path/to/node
## Usage
......
{
'variables': {
'node_iconv_use_system_libiconv%': 0,
},
'targets': [
{
'target_name': 'iconv',
'dependencies': ['libiconv'],
'include_dirs': ['<!(node -e "require(\'nan\')")'],
'sources': ['src/binding.cc'],
'cflags': [
'ccflags': [
'-Wall',
'-Wextra',
'-Wno-unused-parameter', # Squelches warnings coming from v8.h.
......@@ -18,46 +21,42 @@
'GCC_ENABLE_CPP_RTTI': 'NO',
'WARNING_CFLAGS': ['-Wall', '-Wextra', '-Wno-unused-parameter'],
},
},
{
'target_name': 'libiconv',
'type': 'static_library',
'direct_dependent_settings': {
'include_dirs': ['support'],
},
'defines': ['ICONV_CONST=const', 'ENABLE_EXTRA=1'],
'include_dirs': [
'deps/libiconv/srclib',
'support',
],
'sources': ['deps/libiconv/lib/iconv.c'],
'conditions': [
['OS == "win"', {
'defines': ['WIN32_NATIVE=1'],
}, {
'defines': ['HAVE_WORKING_O_NOFOLLOW=1'],
'cflags!': ['-W', '-Wall', '-Wextra'],
['node_iconv_use_system_libiconv==0', {
'defines': ['ICONV_CONST=const', 'ENABLE_EXTRA=1'],
'include_dirs': [
'deps/libiconv/srclib',
'support',
],
'sources': ['deps/libiconv/lib/iconv.c'],
'conditions': [
['OS == "win"', {
'defines': ['WIN32_NATIVE=1'],
}, {
'defines': ['HAVE_WORKING_O_NOFOLLOW=1'],
'cflags!': ['-W', '-Wall', '-Wextra'],
}],
],
'msvs_settings': {
'VCCLCompilerTool': {
'DisableSpecificWarnings': [
'4018', # Signed/unsigned comparison.
'4090', # Const/non-const mismatch.
'4244', # Narrowing cast.
'4267', # Narrowing cast.
],
},
},
'xcode_settings': {
'WARNING_CFLAGS!': ['-W', '-Wall', '-Wextra'],
'WARNING_CFLAGS': [
'-Wno-parentheses-equality',
'-Wno-static-in-inline',
'-Wno-tautological-compare',
],
},
}],
],
'msvs_settings': {
'VCCLCompilerTool': {
'DisableSpecificWarnings': [
'4018', # Signed/unsigned comparison.
'4090', # Const/non-const mismatch.
'4244', # Narrowing cast.
'4267', # Narrowing cast.
],
},
},
'xcode_settings': {
'WARNING_CFLAGS!': ['-W', '-Wall', '-Wextra'],
'WARNING_CFLAGS': [
'-Wno-parentheses-equality',
'-Wno-static-in-inline',
'-Wno-tautological-compare',
],
},
}
]
},
],
}
......@@ -47,7 +47,11 @@ function Iconv(fromEncoding, toEncoding)
var conv = bindings.make(fixEncoding(fromEncoding),
fixEncoding(toEncoding));
if (conv === null) throw new Error('Conversion not supported.');
if (conv === null) {
throw new Error('Conversion from ' +
fromEncoding + ' to ' +
toEncoding + ' is not supported.');
}
var convert_ = convert.bind({ conv_: conv });
var context_ = { trailer: null };
......@@ -88,6 +92,7 @@ util.inherits(Iconv, stream.Stream);
function fixEncoding(encoding)
{
if (/^windows-31j$/i.test(encoding)) return 'cp932';
// Convert "utf8" to "utf-8".
return /^utf[^-]/i.test(encoding) ? 'utf-' + encoding.substr(3) : encoding;
}
......
{
"name": "iconv",
"main": "./lib/iconv",
"version": "2.1.11",
"version": "2.2.1",
"description": "Text recoding in JavaScript for fun and profit!",
"homepage": "https://github.com/bnoordhuis/node-iconv",
"repository": {
......@@ -18,7 +18,7 @@
"license": "ISC",
"readmeFilename": "README.md",
"dependencies": {
"nan": "~2.0.4"
"nan": "^2.3.5"
},
"devDependencies": {
"tap": "~0.4.8"
......
......@@ -22,6 +22,10 @@
#include <assert.h>
#include <stdint.h>
#ifndef ICONV_CONST
#define ICONV_CONST
#endif // ICONV_CONST
namespace
{
......@@ -60,7 +64,7 @@ struct Iconv
static void Initialize(Handle<Object> obj)
{
Local<ObjectTemplate> t = ObjectTemplate::New();
Local<ObjectTemplate> t = Nan::New<ObjectTemplate>();
t->SetInternalFieldCount(1);
object_template.Reset(t);
obj->Set(Nan::New<String>("make").ToLocalChecked(),
......@@ -97,7 +101,7 @@ struct Iconv
Iconv* iv = static_cast<Iconv*>(
Nan::GetInternalFieldPointer(info[0].As<Object>(), 0));
const bool is_flush = info[8]->BooleanValue();
const char* input_buf =
ICONV_CONST char* input_buf =
is_flush ? NULL : node::Buffer::Data(info[1].As<Object>());
size_t input_start = info[2]->Uint32Value();
size_t input_size = info[3]->Uint32Value();
......
......@@ -30,6 +30,9 @@ new Iconv('utf16', 'utf32');
new Iconv('utf16le', 'utf16be');
new Iconv('utf32le', 'utf32be');
// https://github.com/bnoordhuis/node-iconv/issues/152
new Iconv('windows-31J', 'windows-31j');
var iconv = new Iconv('utf-8', 'iso-8859-1');
assert.throws(function() { iconv.convert() });
assert.throws(function() { iconv.convert(1) });
......@@ -44,6 +47,26 @@ assert.deepEqual(iconv.convert(new Buffer('xxx')), new Buffer('xxx'));
var buffer = new Buffer(1); buffer[0] = 235; // ë
assert.deepEqual(iconv.convert('ë'), buffer);
// test conversion error messages
var unknown_conv = 'whatchimajig';
try {
new Iconv('utf-8', unknown_conv);
assert.fail('unreachable');
} catch (e) {
assert.equal(e.message,
'Conversion from utf-8 to ' + unknown_conv +
' is not supported.');
}
try {
new Iconv(unknown_conv, 'utf-8');
assert.fail('unreachable');
} catch (e) {
assert.equal(e.message,
'Conversion from ' + unknown_conv +
' to utf-8 is not supported.');
}
// partial character sequence should throw EINVAL
buffer = new Buffer(1); buffer[0] = 195;
try {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment