Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to set fallback encoding for non-UTF-8 strings. Implements #580. #1039

Merged
merged 2 commits into from
May 6, 2020
Merged
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
1 change: 1 addition & 0 deletions changelog.d/580.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ability to set fallback text encoding for non-UTF-8 messages.
4 changes: 4 additions & 0 deletions config.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,10 @@ ircService:
# Default: 0.0.0.0
address: "::"

# Encoding fallback - which text encoding to try if text is not UTF-8. Default: not set.
# List of supported encodings: https://www.npmjs.com/package/iconv#supported-encodings
# encodingFallback: "ISO-8859-15"

# Configuration for logging. Optional. Default: console debug level logging
# only.
logging:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"extend": "^2.0.0",
"he": "^1.1.1",
"iconv": "^2.3.4",
"irc": "matrix-org/node-irc#matrix-irc-bridge",
"irc": "matrix-org/node-irc#7feccae6c168c2c08527daace0c6fe5af56c6560",
"js-yaml": "^3.2.7",
"logform": "^2.1.2",
"matrix-appservice": "^0.4.1",
Expand Down
1 change: 0 additions & 1 deletion src/bridge/IrcBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export class IrcBridge {
triggerEndpoint: provisioning.enableReload
};
}

let bridgeStoreConfig = {};

if (this.config.database.engine === "nedb") {
Expand Down
1 change: 1 addition & 0 deletions src/config/BridgeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface BridgeConfig {
enabled: boolean;
initial: boolean;
};
encodingFallback: string;
};
sentry?: {
enabled: boolean;
Expand Down
6 changes: 4 additions & 2 deletions src/irc/BridgedClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export class BridgedClient extends EventEmitter {
public readonly isBot: boolean,
private readonly eventBroker: IrcEventBroker,
private readonly identGenerator: IdentGenerator,
private readonly ipv6Generator: Ipv6Generator) {
private readonly ipv6Generator: Ipv6Generator,
private readonly encodingFallback: string) {
super();
this.userId = matrixUser ? matrixUser.getId() : null;
this.displayName = matrixUser ? matrixUser.getDisplayName() : null;
Expand Down Expand Up @@ -220,7 +221,8 @@ export class BridgedClient extends EventEmitter {
// won't be able to turn off IPv6!
localAddress: (
this.server.getIpv6Prefix() ? this.clientConfig.getIpv6Address() : undefined
)
),
encodingFallback: this.encodingFallback,
}, (inst: ConnectionInstance) => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.onConnectionCreated(inst, nameInfo, identResolver!);
Expand Down
3 changes: 2 additions & 1 deletion src/irc/ClientPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ export class ClientPool {

return new BridgedClient(
server, ircClientConfig, matrixUser || undefined, isBot,
this.ircEventBroker, this.identGenerator, this.ipv6Generator
this.ircEventBroker, this.identGenerator, this.ipv6Generator,
this.ircBridge.config.ircService.encodingFallback
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/irc/ConnectionInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export interface ConnectionOpts {
secure?: {
ca?: string;
};
encodingFallback: string;
}

export type InstanceDisconnectReason = "throttled"|"irc_error"|"net_error"|"timeout"|"raw_error"|
Expand Down Expand Up @@ -383,6 +384,7 @@ export class ConnectionInstance {
bustRfc3484: true,
sasl: opts.password ? server.useSasl() : false,
secure: server.useSsl() ? { ca: server.getCA() } : undefined,
encodingFallback: opts.encodingFallback
};

// Returns: A promise which resolves to a ConnectionInstance
Expand Down