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
54 changes: 54 additions & 0 deletions credentials/FirebirdApi.credentials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,59 @@ export class FirebirdApi implements ICredentialType {
default: false,
description: 'Set to true to lowercase keys.',
},
{
displayName: 'Charset',
name: 'charset',
type: 'options',
options: [
{
name: 'UTF8',
value: 'UTF8',
},
{
name: 'WIN1252',
value: 'WIN1252',
},
{
name: 'ISO8859_1',
value: 'ISO8859_1',
},
{
name: 'WIN1251',
value: 'WIN1251',
},
{
name: 'WIN1250',
value: 'WIN1250',
},
{
name: 'ASCII',
value: 'ASCII',
},
{
name: 'NONE',
value: 'NONE',
},
],
default: 'UTF8',
description: 'Character set for the database connection.',
},
{
displayName: 'Dialect',
name: 'dialect',
type: 'options',
options: [
{
name: 'Dialect 1',
value: 1,
},
{
name: 'Dialect 3',
value: 3,
},
],
default: 3,
description: 'SQL dialect version for the database connection. Dialect 3 is recommended for modern Firebird databases.',
},
];
}
Binary file added n8n-nodes-firebird-0.0.5.tgz
Binary file not shown.
Binary file added n8n-nodes-firebird-1.0.0.tgz
Binary file not shown.
Binary file added n8n-nodes-firebird-1.0.1.tgz
Binary file not shown.
Binary file added n8n-nodes-firebird-custom-1.0.0.tgz
Binary file not shown.
103 changes: 101 additions & 2 deletions nodes/Firebird/Firebird.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
INodeExecutionData,
INodeType,
INodeTypeDescription,
NodeConnectionType,
NodeOperationError,
} from "n8n-workflow";
// @ts-ignore
Expand All @@ -15,6 +16,87 @@ import * as fbd from "node-firebird";
import { copyInputItems } from "./GenericFunctions";
import { queryOperationOptions } from "./operations";

// Helper function to fix common character encoding issues
function fixStringEncoding(str: string): string {
if (!str || typeof str !== 'string') {
return str;
}

try {
// Only apply fixes if the string contains obvious encoding artifacts
// This prevents fixing already correct strings
if (!str.includes('Ã') && !str.includes('Â') && !str.includes('â€') && !str.includes('��')) {
return str; // String looks fine, don't touch it
}

let fixed = str;

// Handle specific double-encoded UTF-8 patterns (Windows-1252 → UTF-8 issues)
// These are the most common patterns for Portuguese/Spanish
const encodingFixes = [
// Common Portuguese/Spanish vowels with accents
[/ç/g, 'ç'], // ç
[/á/g, 'á'], // á
[/é/g, 'é'], // é
[/í/g, 'í'], // í
[/ó/g, 'ó'], // ó
[/ú/g, 'ú'], // ú
[/Ã /g, 'à'], // à
[/â/g, 'â'], // â
[/ê/g, 'ê'], // ê
[/ô/g, 'ô'], // ô
[/ã/g, 'ã'], // ã
[/ñ/g, 'ñ'], // ñ

// Less common but still important
[/è/g, 'è'], // è
[/ì/g, 'ì'], // ì
[/ò/g, 'ò'], // ò
[/ù/g, 'ù'], // ù

// Uppercase variants
[/À/g, 'À'], // À
[/Ã/g, 'Á'], // Á
[/Â/g, 'Â'], // Â
[/Ã/g, 'Ã'], // Ã
[/É/g, 'É'], // É
[/Ê/g, 'Ê'], // Ê
[/Ã/g, 'Í'], // Í
[/Ã"/g, 'Ó'], // Ó
[/Ã"/g, 'Ô'], // Ô
[/Õ/g, 'Õ'], // Õ
[/Ú/g, 'Ú'], // Ú
[/Ç/g, 'Ç'], // Ç

// Special characters
[/°/g, 'º'], // º (masculine ordinal)
[/ª/g, 'ª'], // ª (feminine ordinal)

// Smart quotes and dashes (be very specific)
[/’/g, "'"], // Smart apostrophe
[/“/g, '"'], // Smart quote left
[/â€/g, '"'], // Smart quote right (but be careful)
[/â€"/g, '–'], // En dash
[/â€"/g, '—'], // Em dash
];

// Apply each fix
for (const [pattern, replacement] of encodingFixes) {
fixed = fixed.replace(pattern as RegExp, replacement as string);
}

// Handle the specific cases mentioned, but be more careful
// Only replace �� when it's likely at the end of words that should end in -ção
fixed = fixed.replace(/(\w+)��o\b/g, '$1ção'); // More targeted replacement

return fixed;

} catch (error) {
// If all else fails, return the original string
return str;
}
}

export class Firebird implements INodeType {
description: INodeTypeDescription = {
displayName: "Firebird",
Expand All @@ -30,8 +112,8 @@ export class Firebird implements INodeType {
defaults: {
name: "Firebird",
},
inputs: ["main"],
outputs: ["main"],
inputs: [NodeConnectionType.Main],
outputs: [NodeConnectionType.Main],
credentials: [
{
name: "firebirdApi",
Expand Down Expand Up @@ -132,6 +214,23 @@ export class Firebird implements INodeType {
});
});
}

// Handle character encoding for text fields
if (Array.isArray(result)) {
result = result.map(row => {
const processedRow: any = {};
for (const [key, value] of Object.entries(row)) {
if (typeof value === 'string') {
// Try to fix common encoding issues
processedRow[key] = fixStringEncoding(value);
} else {
processedRow[key] = value;
}
}
return processedRow;
});
}

return result;
}),
)) as any[]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "n8n-nodes-firebird",
"version": "0.0.3",
"version": "0.0.5",
"description": "Firebird node for n8n.",
"keywords": [
"n8n-community-node-package",
Expand Down