Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseBbCode(str) {
if (typeof str != 'string') {
// Don't try to process non-string values, e.g. null
return str;
}
// Steam will put a backslash in front of a bracket for a BBCode tag that shouldn't be parsed as BBCode, but our
// parser doesn't ignore those. Let's just replace "\\[" with some string that's very improbable to exist in a Steam
// chat message, then replace it again later.
let replacement = Crypto.randomBytes(32).toString('hex');
str = str.replace(/\\\[/g, replacement);
let parsed = BBCode.parse(str, {
"onlyAllowTags": [
"emoticon",
"code",
"pre",
"img",
"url",
"spoiler",
"quote",
"random",
"flip",
"tradeofferlink",
"tradeoffer"
]
});
return collapseStrings(parsed.map(processTagNode));