mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
feat: fixed tokenization strategy
This commit is contained in:
@@ -20,10 +20,16 @@ const vowelRegex = new RE2(/^[aeiou]/i);
|
||||
|
||||
export const startsWithVowel = (str: string) => vowelRegex.test(str);
|
||||
|
||||
const pickWordsRegex = new RE2(/(\W+)/);
|
||||
export const sanitizeString = (dto: { unsanitizedString: string; tokens: string[] }) => {
|
||||
let sanitizedString = dto.unsanitizedString;
|
||||
dto.tokens.filter(Boolean).forEach((el) => {
|
||||
sanitizedString = sanitizedString.replaceAll(el, "[REDACTED]");
|
||||
const words = dto.unsanitizedString.split(pickWordsRegex);
|
||||
|
||||
const redactionSet = new Set(dto.tokens.filter(Boolean));
|
||||
const sanitizedWords = words.map((el) => {
|
||||
if (redactionSet.has(el)) {
|
||||
return "[REDACTED]";
|
||||
}
|
||||
return el;
|
||||
});
|
||||
return sanitizedString;
|
||||
return sanitizedWords.join("");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user