8000 Ś╫êëτ⌡ś and Š╫ěéτ⌡š · SheetJS/sheetjs@6a5be04 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6a5be04

Browse files
committed
Ś╫êëτ⌡ś and Š╫ěéτ⌡š
1 parent e90a61b commit 6a5be04

File tree

14 files changed

+129
-22
lines changed

14 files changed

+129
-22
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ test.ts: test.mts
148148
node -pe 'var data = fs.readFileSync("'$<'", "utf8"); data.split("\n").map(function(l) { return l.replace(/^describe\((.*?)function\(\)/, "Deno.test($$1async function(t)").replace(/\b(?:it|describe)\((.*?)function\(\)/g, "await t.step($$1async function(t)").replace("assert.ok", "assert.assert"); }).join("\n")' > $@
149149

150150
.PHONY: test-bun
151-
test-bun: hotcross.mjs ## Run Bun test suite
151+
test-bun: testbun.mjs ## Run Bun test suite
152152
bun $<
153153

154154
.PHONY: test-deno

bits/23_binutils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ function WriteShift(t/*:number*/, val/*:string|number*/, f/*:?string*/)/*:any*/
191191
}
192192
size = val.length;
193193
} else if(typeof $cptable !== 'undefined' && f == 'cpstr') {
194-
cpp = $cptable.utils.encode(current_ansi, val);
194+
cpp = $cptable.utils.encode(current_codepage, val);
195195
/* replace null bytes with _ when relevant */
196196
if(cpp.length == val.length) for(i = 0; i < val.length; ++i) if(cpp[i] == 0 && val.charCodeAt(i) != 0) cpp[i] = 0x5F;
197197
if(cpp.length == 2 * val.length) for(i = 0; i < val.length; ++i) if(cpp[2*i] == 0 && cpp[2*i+1] == 0 && val.charCodeAt(i) != 0) cpp[2*i] = 0x5F;

bits/40_harb.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* from js-harb (C) 2014-present SheetJS */
21
var DBF_SUPPORTED_VERSIONS = [0x02, 0x03, 0x30, 0x31, 0x83, 0x8B, 0x8C, 0xF5];
32
var DBF = /*#__PURE__*/(function() {
43
var dbf_codepage_map = {
@@ -247,6 +246,7 @@ function dbf_to_workbook(buf, opts)/*:Workbook*/ {
247246
var _RLEN = { 'B': 8, 'C': 250, 'L': 1, 'D': 8, '?': 0, '': 0 };
248247
function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) {
249248
var o = opts || {};
249+
var old_cp = current_codepage;
250250
if(+o.codepage >= 0) set_cp(+o.codepage);
251251
if(o.type == "string") throw new Error("Cannot write DBF to JS string");
252252
var ba = buf_array();
@@ -309,11 +309,17 @@ function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) {
309309
h.write_shift(2, 296 + 32 * hcnt);
310310
h.write_shift(2, rlen);
311311
for(i=0; i < 4; ++i) h.write_shift(4, 0);
312-
h.write_shift(4, 0x00000000 | ((+dbf_reverse_map[/*::String(*/current_ansi/*::)*/] || 0x03)<<8));
312+
var cp = +dbf_reverse_map[/*::String(*/current_codepage/*::)*/] || 0x03;
313+
h.write_shift(4, 0x00000000 | (cp<<8));
314+
if(dbf_codepage_map[cp] != +o.codepage) {
315+
console.error("DBF Unsupported codepage " + current_codepage + ", using 1252");
316+
current_codepage = 1252;
317+
}
313318

314319
for(i = 0, j = 0; i < headers.length; ++i) {
315320
if(headers[i] == null) continue;
316321
var hf = ba.next(32);
322+
/* TODO: test how applications handle non-ASCII field names */
317323
var _f = (headers[i].slice(-10) + "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00").slice(0, 11);
318324
hf.write_shift(1, _f, "sbcs");
319325
hf.write_shift(1, coltypes[i] == '?' ? 'C' : coltypes[i], "sbcs");
@@ -362,6 +368,7 @@ function sheet_to_dbf(ws/*:Worksheet*/, opts/*:WriteOpts*/) {
362368
}
363369
// data
364370
}
371+
current_codepage = old_cp;
365372
ba.next(1).write_shift(1, 0x1A);
366373
return ba.end();
367374
}

test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2399,6 +2399,16 @@ describe('dbf', function() {
23992399
["I2", "v", true], ["L2", "v", "SheetJS"]
24002400
].forEach(function(r) { assert.equal(get_cell(ws, r[0])[r[1]], r[2]); });
24012401
});
2402+
if(!browser || typeof cptable !== 'undefined') it("Ś╫êëτ⌡ś and Š╫ěéτ⌡š", function() {
2403+
[ [620, "Ś╫êëτ⌡ś"], [895, "Š╫ěéτ⌡š"] ].forEach(function(r) {
2404+
var book = X.utils.book_new();
2405+
var sheet = X.utils.aoa_to_sheet([["ASCII", "encoded"], ["Test", r[1]]]);
2406+
X.utils.book_append_sheet(book, sheet, "sheet1");
2407+
var data = X.write(book, {type: TYPE, bookType: "dbf", codepage:r[0]});
2408+
var wb = X.read(data, {type: TYPE});
2409+
assert.equal(wb.Sheets.Sheet1.B2.v, r[1]);
2410+
});
2411+
});
24022412
});
24032413
var JSDOM = null;
24042414
// $FlowIgnore

test.mjs

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test.mts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,14 @@ describe('CSV', function() {
21602160
["3a", "3 a", "3 a-1"],
21612161
["3b", "3 b", "3 b-1"],
21622162
["3p", "3 P", "3 p-1"],
2163-
]
2163+
];
21642164
var ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true}).Sheets.Sheet1;
21652165
for(var R = 0; R < 3; ++R) {
21662166
assert.equal(get_cell(ws, "A" + (R+1)).v, aoa[R][0]);
21672167
assert.equal(get_cell(ws, "C" + (R+1)).v, aoa[R][2]);
21682168
}
21692169
assert.equal(get_cell(ws, "B2").v, "3 b");
2170-
var B1 = get_cell(ws, "B1"); console.log(B1); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
2170+
var B1 = get_cell(ws, "B1"); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
21712171
var B3 = get_cell(ws, "B3"); assert.equal(B3.t, "d"); assert.equal(B3.v.getHours(), 15);
21722172
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: false}).Sheets.Sheet1;
21732173
for(var R = 0; R < 3; ++R) {
@@ -2326,6 +2326,16 @@ describe('dbf', function() {
23262326
["I2", "v", true], ["L2", "v", "SheetJS"]
23272327
] as Array<[string, string, any]>).forEach(function(r) { assert.equal(get_cell(ws, r[0])[r[1]], r[2]); });
23282328
});
2329+
it("Ś╫êëτ⌡ś and Š╫ěéτ⌡š", function() {
2330+
([ [620, "Ś╫êëτ⌡ś"], [895, "Š╫ěéτ⌡š"] ] as Array<[number,string]>).forEach(function(r) {
2331+
var book = X.utils.book_new();
2332+
var sheet = X.utils.aoa_to_sheet([["ASCII", "encoded"], ["Test", r[1]]]);
2333+
X.utils.book_append_sheet(book, sheet, "sheet1");
2334+
var data = X.write(book, {type: TYPE, bookType: "dbf", codepage:r[0]});
2335+
var wb = X.read(data, {type: TYPE});
2336+
assert.equal(wb.Sheets.Sheet1.B2.v, r[1]);
2337+
});
2338+
});
23292339
});
23302340
import { JSDOM } from 'jsdom';
23312341
var domtest = false; // error: Error: Not implemented: isContext

test.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,14 @@ Deno.test('CSV', async function(t) {
21602160
["3a", "3 a", "3 a-1"],
21612161
["3b", "3 b", "3 b-1"],
21622162
["3p", "3 P", "3 p-1"],
2163-
]
2163+
];
21642164
var ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true}).Sheets.Sheet1;
21652165
for(var R = 0; R < 3; ++R) {
21662166
assert.equal(get_cell(ws, "A" + (R+1)).v, aoa[R][0]);
21672167
assert.equal(get_cell(ws, "C" + (R+1)).v, aoa[R][2]);
21682168
}
21692169
assert.equal(get_cell(ws, "B2").v, "3 b");
2170-
var B1 = get_cell(ws, "B1"); console.log(B1); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
2170+
var B1 = get_cell(ws, "B1"); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
21712171
var B3 = get_cell(ws, "B3"); assert.equal(B3.t, "d"); assert.equal(B3.v.getHours(), 15);
21722172
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: false}).Sheets.Sheet1;
21732173
for(var R = 0; R < 3; ++R) {
@@ -2326,6 +2326,16 @@ Deno.test('dbf', async function(t) {
23262326
["I2", "v", true], ["L2", "v", "SheetJS"]
23272327
] as Array<[string, string, any]>).forEach(function(r) { assert.equal(get_cell(ws, r[0])[r[1]], r[2]); });
23282328
});
2329+
await t.step("Ś╫êëτ⌡ś and Š╫ěéτ⌡š", async function(t) {
2330+
([ [620, "Ś╫êëτ⌡ś"], [895, "Š╫ěéτ⌡š"] ] as Array<[number,string]>).forEach(function(r) {
2331+
var book = X.utils.book_new();
2332+
var sheet = X.utils.aoa_to_sheet([["ASCII", "encoded"], ["Test", r[1]]]);
2333+
X.utils.book_append_sheet(book, sheet, "sheet1");
2334+
var data = X.write(book, {type: TYPE, bookType: "dbf", codepage:r[0]});
2335+
var wb = X.read(data, {type: TYPE});
2336+
assert.equal(wb.Sheets.Sheet1.B2.v, r[1]);
2337+
});
2338+
});
23292339
});
23302340
import { JSDOM } from 'jsdom';
23312341
var domtest = false; // error: Error: Not implemented: isContext
File renamed without changes.

testnocp.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2159,14 +2159,14 @@ Deno.test('CSV', async function(t) {
21592159
["3a", "3 a", "3 a-1"],
21602160
["3b", "3 b", "3 b-1"],
21612161
["3p", "3 P", "3 p-1"],
2162-
]
10000 2162+
];
21632163
var ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: true}).Sheets.Sheet1;
21642164
for(var R = 0; R < 3; ++R) {
21652165
assert.equal(get_cell(ws, "A" + (R+1)).v, aoa[R][0]);
21662166
assert.equal(get_cell(ws, "C" + (R+1)).v, aoa[R][2]);
21672167
}
21682168
assert.equal(get_cell(ws, "B2").v, "3 b");
2169-
var B1 = get_cell(ws, "B1"); console.log(B1); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
2169+
var B1 = get_cell(ws, "B1"); assert.equal(B1.t, "d"); assert.equal(B1.v.getHours(), 3);
21702170
var B3 = get_cell(ws, "B3"); assert.equal(B3.t, "d"); assert.equal(B3.v.getHours(), 15);
21712171
ws = X.read(aoa.map(function(row) { return row.join(","); }).join("\n"), {type: "string", cellDates: false}).Sheets.Sheet1;
21722172
for(var R = 0; R < 3; ++R) {
@@ -2325,6 +2325,16 @@ Deno.test('dbf', async function(t) {
23252325
["I2", "v", true], ["L2", "v", "SheetJS"]
23262326
] as Array<[string, string, any]>).forEach(function(r) { assert.equal(get_cell(ws, r[0])[r[1]], r[2]); });
23272327
});
2328+
if(false) await t.step("Ś╫êëτ⌡ś and Š╫ěéτ⌡š", async function(t) {
2329+
([ [620, "Ś╫êëτ⌡ś"], [895, "Š╫ěéτ⌡š"] ] as Array<[number,string]>).forEach(function(r) {
2330+
var book = X.utils.book_new();
2331+
var sheet = X.utils.aoa_to_sheet([["ASCII", "encoded"], ["Test", r[1]]]);
2332+
X.utils.book_append_sheet(book, sheet, "sheet1");
2333+
var data = X.write(book, {type: TYPE, bookType: "dbf", codepage:r[0]});
2334+
var wb = X.read(data, {type: TYPE});
2335+
assert.equal(wb.Sheets.Sheet1.B2.v, r[1]);
2336+
});
2337+
});
23282338
});
23292339
import { JSDOM } from 'jsdom';
23302340
var domtest = false; // error: Error: Not implemented: isContext

tests/core.js

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
294E
0