fix(Spreadsheet File Node): Read file as utf-8 in v1 (#7701)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Elias Meire 2023-11-14 11:27:37 +01:00 committed by GitHub
parent 0e00dab9f5
commit 786b4adcce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 111 additions and 0 deletions

View file

@ -178,6 +178,22 @@ describe('Execute Spreadsheet File Node', () => {
},
},
},
{
description: 'execute utf8.json',
input: {
workflowData: loadWorkflow('workflow.utf8.json', 'utf8.csv'),
},
output: {
nodeData: {
'Parse UTF8 v1': [
[{ json: { A: 1, B: '株式会社', C: 3 } }, { json: { A: 4, B: 5, C: '🐛' } }],
],
'Parse UTF8 v2': [
[{ json: { A: '1', B: '株式会社', C: '3' } }, { json: { A: '4', B: '5', C: '🐛' } }],
],
},
},
},
];
const nodeTypes = Helpers.setup(tests);

View file

@ -0,0 +1,3 @@
A,B,C
1,株式会社,3
4,5,🐛
1 A B C
2 1 株式会社 3
3 4 5 🐛

View file

@ -0,0 +1,91 @@
{
"meta": {
"instanceId": "78577815012af39cf16dad7a787b0898c42fb7514b8a7f99b2136862c2af502c"
},
"nodes": [
{
"parameters": {},
"id": "2130ab19-2efb-4217-b234-f8607d4122cc",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [
260,
460
]
},
{
"parameters": {
"options": {
"readAsString": true
}
},
"id": "68e03042-aa27-43db-bfec-3c4fe07ce9f6",
"name": "Parse UTF8 v1",
"type": "n8n-nodes-base.spreadsheetFile",
"typeVersion": 1,
"position": [
760,
360
]
},
{
"parameters": {
"fileFormat": "csv",
"options": {
"readAsString": true
}
},
"id": "6a8b7ee9-5d14-4b67-b7cc-afee6bcc1fa6",
"name": "Parse UTF8 v2",
"type": "n8n-nodes-base.spreadsheetFile",
"typeVersion": 2,
"position": [
760,
560
]
},
{
"parameters": {
"fileSelector": "utf8.csv"
},
"id": "623ea890-8882-4273-973e-834652d823b5",
"name": "Read Binary File",
"type": "n8n-nodes-base.readBinaryFiles",
"typeVersion": 1,
"position": [
480,
460
]
}
],
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Read Binary File",
"type": "main",
"index": 0
}
]
]
},
"Read Binary File": {
"main": [
[
{
"node": "Parse UTF8 v1",
"type": "main",
"index": 0
},
{
"node": "Parse UTF8 v2",
"type": "main",
"index": 0
}
]
]
}
}
}

View file

@ -77,6 +77,7 @@ export class SpreadsheetFileV1 implements INodeType {
if (binaryData.id) {
const binaryPath = this.helpers.getBinaryPath(binaryData.id);
xlsxOptions.codepage = 65001; // utf8 codepage
workbook = xlsxReadFile(binaryPath, xlsxOptions);
} else {
const binaryDataBuffer = Buffer.from(binaryData.data, BINARY_ENCODING);