use super::TaintLang;
use tree_sitter::Node;
const JS_COERCIONS: &[&str] = &["Number", "parseInt", "parseFloat", "BigInt", "Boolean"];
const PY_COERCIONS: &[&str] = &["int", "float", "bool"];
const GO_COERCIONS: &[&str] = &[
"strconv.Atoi",
"strconv.ParseInt",
"strconv.ParseFloat",
"strconv.ParseBool",
];
pub(super) fn is_sanitizer_call(node: Node<'_>, content: &str, lang: TaintLang) -> bool {
let is_call = match lang {
TaintLang::Js | TaintLang::Go => node.kind() == "call_expression",
TaintLang::Python => node.kind() == "call",
};
if !is_call {
return false;
}
let Some(callee) = node.child_by_field_name("function") else {
return false;
};
let text = callee.utf8_text(content.as_bytes()).unwrap_or("").trim();
let coercions = match lang {
TaintLang::Js => JS_COERCIONS,
TaintLang::Python => PY_COERCIONS,
TaintLang::Go => GO_COERCIONS,
};
coercions.contains(&text)
}