Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ iconv.decode = function decode(buf, encoding, options) {
var res = decoder.write(buf);
var trail = decoder.end();

return trail ? (res + trail) : res;
var res = trail ? (res + trail) : res;
if (res.indexOf('�') !== -1 && options && options.invalidCharHandler) res = options.invalidCharHandler()
return res
}

iconv.encodingExists = function encodingExists(enc) {
Expand Down
14 changes: 14 additions & 0 deletions test/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ var testStringLatin1 = "Hello123!£Å÷×çþÿ¿®";
var testStringBase64 = "SGVsbG8xMjMh";
var testStringHex = "48656c6c6f31323321";

describe("user callback", function () {
it("Return nothing for issue#210#83", function () {
// when bad characters, return nothing instead of the ?.
// Like these:
// iconv.decode(Buffer.from([128]), 'utf8')
// iconv.decode(iconv.encode('ça va','utf8'), 'utf7')
assert.strictEqual(iconv.decode(Buffer.from([128]), 'utf8', {
invalidCharHandler: function () {
return ''
}
}), '');
})
})

describe("Generic UTF8-UCS2 tests", function() {

it("Return values are of correct types", function() {
Expand Down