-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
23 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { InterpolationObject } from "./types"; | ||
import sanitizeText from "./sanitizeText"; | ||
|
||
export default function replaceInterps(str: string, interp?: InterpolationObject) { | ||
console.log(interp) | ||
for (const key in interp) { | ||
str = str.replaceAll(`{{${key}}}`, interp[key] as string); | ||
// sanitize the key to prevent XSS | ||
str = str.replaceAll(`{{${key}}}`, sanitizeText(interp[key] as string)); | ||
} | ||
return str; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const entityMap = { | ||
'&': '&', | ||
'<': '<', | ||
'>': '>', | ||
// '"': '"', | ||
// "'": ''', | ||
// '/': '/', | ||
// '`': '`', | ||
// '=': '=' | ||
}; | ||
|
||
export default function sanitizeText(text: string) { | ||
return text.replace(/[&<>]/g, function (s) { | ||
// @ts-ignore should be fine :clueless: | ||
return entityMap[s]; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters