mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 05:27:52 +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);
|
export const startsWithVowel = (str: string) => vowelRegex.test(str);
|
||||||
|
|
||||||
|
const pickWordsRegex = new RE2(/(\W+)/);
|
||||||
export const sanitizeString = (dto: { unsanitizedString: string; tokens: string[] }) => {
|
export const sanitizeString = (dto: { unsanitizedString: string; tokens: string[] }) => {
|
||||||
let sanitizedString = dto.unsanitizedString;
|
const words = dto.unsanitizedString.split(pickWordsRegex);
|
||||||
dto.tokens.filter(Boolean).forEach((el) => {
|
|
||||||
sanitizedString = sanitizedString.replaceAll(el, "[REDACTED]");
|
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