Improve logging in VoiceNotesPlaybackContext
This commit is contained in:
parent
03ab5b4b34
commit
01581b04d8
3 changed files with 62 additions and 16 deletions
|
@ -22,6 +22,7 @@ const GROUP_V2_ID_PATTERN = /(groupv2\()([^=)]+)(=?=?\))/g;
|
|||
const CALL_LINK_ROOM_ID_PATTERN = /[0-9A-F]{61}([0-9A-F]{3})/gi;
|
||||
const CALL_LINK_ROOT_KEY_PATTERN =
|
||||
/([A-Z]{4})-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}-[A-Z]{4}/gi;
|
||||
const ATTACHMENT_URL_KEY_PATTERN = /(attachment:\/\/[^\s]+key=)([^\s]+)/gi;
|
||||
const REDACTION_PLACEHOLDER = '[REDACTED]';
|
||||
|
||||
export type RedactFunction = (value: string) => string;
|
||||
|
@ -163,6 +164,14 @@ export const redactCallLinkRootKeys = (text: string): string => {
|
|||
return text.replace(CALL_LINK_ROOT_KEY_PATTERN, `${REDACTION_PLACEHOLDER}$1`);
|
||||
};
|
||||
|
||||
export const redactAttachmentUrlKeys = (text: string): string => {
|
||||
if (!isString(text)) {
|
||||
throw new TypeError("'text' must be a string");
|
||||
}
|
||||
|
||||
return text.replace(ATTACHMENT_URL_KEY_PATTERN, `$1${REDACTION_PLACEHOLDER}`);
|
||||
};
|
||||
|
||||
export const redactCdnKey = (cdnKey: string): string => {
|
||||
return `${REDACTION_PLACEHOLDER}${cdnKey.slice(-3)}`;
|
||||
};
|
||||
|
@ -171,6 +180,16 @@ export const redactGenericText = (text: string): string => {
|
|||
return `${REDACTION_PLACEHOLDER}${text.slice(-3)}`;
|
||||
};
|
||||
|
||||
export const redactAttachmentUrl = (urlString: string): string => {
|
||||
try {
|
||||
const url = new URL(urlString);
|
||||
url.search = '';
|
||||
return url.toString();
|
||||
} catch {
|
||||
return REDACTION_PLACEHOLDER;
|
||||
}
|
||||
};
|
||||
|
||||
const createRedactSensitivePaths = (
|
||||
paths: ReadonlyArray<string>
|
||||
): RedactFunction => {
|
||||
|
@ -194,7 +213,8 @@ export const redactAll: RedactFunction = compose(
|
|||
redactPhoneNumbers,
|
||||
redactUuids,
|
||||
redactCallLinkRoomIds,
|
||||
redactCallLinkRootKeys
|
||||
redactCallLinkRootKeys,
|
||||
redactAttachmentUrlKeys
|
||||
);
|
||||
|
||||
const removeNewlines: RedactFunction = text => text.replace(/\r?\n|\r/g, '');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue