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

Fix bugs in handling server names that includes colons #999

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions changelog.d/999.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bugs in handling server names that includes colons
2 changes: 1 addition & 1 deletion src/Connections/GenericHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
if (!this.config.userIdPrefix) {
return this.intent.userId;
}
const [, domain] = this.intent.userId.split(':');
const domain = this.intent.userId.substring(this.intent.userId.indexOf(':')+1);
const name = this.state.name &&
this.state.name.replace(/[A-Z]/g, (s) => s.toLowerCase()).replace(/([^a-z0-9\-.=_]+)/g, '');
return `@${this.config.userIdPrefix}${name || 'bot'}:${domain}`;
Expand All @@ -355,7 +355,7 @@
if (this.cachedDisplayname !== expectedDisplayname) {
this.cachedDisplayname = (await intent.underlyingClient.getUserProfile(this.intent.userId)).displayname;
}
} catch (ex) {

Check warning on line 358 in src/Connections/GenericHook.ts

View workflow job for this annotation

GitHub Actions / lint-node

'ex' is defined but never used
// Couldn't fetch, probably not set.
this.cachedDisplayname = undefined;
}
Expand Down
16 changes: 6 additions & 10 deletions src/config/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,10 @@ impl BridgePermissions {
service: String,
permission: String,
) -> napi::Result<bool> {
let parts: Vec<&str> = mxid.split(':').collect();
let permission_int = permission_level_to_int(permission)?;
let domain = if parts.len() > 1 {
parts[1].to_string()
} else {
parts[0].to_string()
let domain: String = match mxid.split_once(':') {
Some((.., d)) => d.to_string(),
None => return Ok(false),
};
for actor_permission in self.config.iter() {
// Room_id
Expand All @@ -128,12 +126,10 @@ impl BridgePermissions {

#[napi]
pub fn check_action_any(&self, mxid: String, permission: String) -> napi::Result<bool> {
let parts: Vec<&str> = mxid.split(':').collect();
let permission_int = permission_level_to_int(permission)?;
let domain = if parts.len() > 1 {
parts[1].to_string()
} else {
parts[0].to_string()
let domain: String = match mxid.split_once(':') {
Some((.., d)) => d.to_string(),
None => return Ok(false),
};
for actor_permission in self.config.iter() {
if !self.match_actor(actor_permission, &domain, &mxid) {
Expand Down
Loading