The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/lib/ldap/operations/match.ts

28 lines
806 B

export type LDAPVariableMatch = {
operation: 'match';
pattern: string;
regex?: boolean;
flags?: string;
indexToUse?: number;
valueIfTrue?: string;
valueIfFalse?: string;
};
export function executeMatch(input: string, operation: LDAPVariableMatch): string | undefined {
if (!operation.pattern || (typeof operation.valueIfTrue !== 'string' && typeof operation.indexToUse !== 'number')) {
throw new Error('Invalid MATCH operation.');
}
const pattern = operation.regex ? new RegExp(operation.pattern, operation.flags) : operation.pattern;
const result = input.match(pattern);
if (!result) {
return operation.valueIfFalse;
}
if (typeof operation.indexToUse === 'number' && result.length > operation.indexToUse) {
return result[operation.indexToUse];
}
return operation.valueIfTrue;
}