File: use-glibc-iconv.patch

package info (click to toggle)
node-iconv 3.0.1%2B~3.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 5,836 kB
  • sloc: ansic: 90,732; javascript: 448; makefile: 7
file content (113 lines) | stat: -rw-r--r-- 3,678 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
Description: use system iconv from glibc
 1) do not build bundled iconv
 2) work around eglibc libiconv implementation, that is:
  * do not throw when //translit is on
  * set LC_CTYPE to "C.UTF-8" to get previsible //translit behavior.
    This is a feature a debian's libc6 implementation.
  * codepages CP858 CP853 CP943 are not available
Forwarded: not-needed
Author: Jérémy Lal <kapouer@melix.org>
Reviewed-By: Yadd <yadd@debian.org>
Last-Update: 2021-11-29

--- a/binding.c
+++ b/binding.c
@@ -14,13 +14,14 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-#include "iconv.h"
-#include "node_api.h"
+#include <iconv.h>
+#include <node_api.h>
 
 #include <assert.h>
 #include <errno.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include <locale.h>
 
 #ifndef E2BIG
 #define E2BIG 0
@@ -222,6 +223,7 @@
 	EXPORT_VALUE(&props[2], E2BIG);
 	EXPORT_VALUE(&props[3], EILSEQ);
 	EXPORT_VALUE(&props[4], EINVAL);
+	setlocale(LC_CTYPE, "C.UTF-8");
 	napi_define_properties(env, exports, ARRAY_SIZE(props), props);
 
 	return exports;
--- a/index.js
+++ b/index.js
@@ -46,21 +46,24 @@
   stream.Stream.call(this);
   this.writable = true;
 
-  const conv = bindings.make(fixEncoding(fromEncoding),
-                             fixEncoding(toEncoding));
+  const fixedFrom = fixEncoding(fromEncoding);
+  const fixedTo = fixEncoding(toEncoding);
+
+  const conv = bindings.make(fixedFrom, fixedTo);
   if (conv === null) {
     throw new Error('Conversion from ' +
                     fromEncoding + ' to ' +
                     toEncoding + ' is not supported.');
   }
 
-  const context_ = { trailer: null };
+  const context_ = { trailer: null, from: fixedFrom, to: fixedTo };
 
   this.convert = function(input, encoding) {
     if (typeof(input) === 'string') {
       input = Buffer.from(input, encoding || 'utf8');
     }
-    return convert(conv, input, null);
+    context_.none = true;
+    return convert(conv, input, context_);
   };
 
   this.write = function(input, encoding) {
@@ -102,10 +105,10 @@
   if (!Buffer.isBuffer(input) && input !== FLUSH) {
     throw new Error('Bad argument.');  // Not a buffer or a string.
   }
-  if (context !== null && context.trailer !== null && input === FLUSH) {
+  if (context.trailer !== null && input === FLUSH) {
     throw errnoException('EINVAL', 'Incomplete character sequence.');
   }
-  if (context !== null && context.trailer !== null) {
+  if (context.trailer !== null) {
     if (input.length === 0) {
       // Use the trailer directly when the input is empty,
       // don't allocate a new buffer.
@@ -151,10 +154,12 @@
         continue;
       }
       else if (errno === EILSEQ) {
-        throw errnoException('EILSEQ', 'Illegal character sequence.');
+        if (/\/\/ignore/i.test(context.to) == false) {
+          throw errnoException('EILSEQ', 'Illegal character sequence.');
+        }
       }
       else if (errno === EINVAL) {
-        if (context === null || input === FLUSH) {
+        if (context.none || input === FLUSH) {
           throw errnoException('EINVAL', 'Incomplete character sequence.');
         }
         else {
--- a/test/test-basic.js
+++ b/test/test-basic.js
@@ -142,10 +142,10 @@
 assert.equal(iconv.convert('b2s=', 'base64').toString(), 'ok');
 
 const aixEncodings =
-    'CP856 CP922 CP943 CP1046 CP1124 CP1129 CP1161 CP1162 CP1163';
+    'CP856 CP922 CP1046 CP1124 CP1129 CP1161 CP1162 CP1163';
 
 const dosEncodings =
-    'CP437 CP737 CP775 CP852 CP853 CP855 CP857 CP858 CP860 CP861 ' +
+    'CP437 CP737 CP775 CP852 CP855 CP857 CP860 CP861 ' +
     'CP863 CP864 CP865 CP869 CP1125';
 
 // Check that AIX and DOS encodings are available.