validateExpressionDepth function
Giới hạn độ sâu lồng nhau của MapLibre expression (§9.8 protocol, mặc định 5). Chặn expression bệnh hoạn gây tốn CPU khi render.
Implementation
bool validateExpressionDepth(
Object? expr, {
int maxDepth = 5,
int currentDepth = 1,
}) {
if (currentDepth > maxDepth) return false;
if (expr is! List) return true;
for (final item in expr) {
if (item is List &&
!validateExpressionDepth(
item,
maxDepth: maxDepth,
currentDepth: currentDepth + 1,
)) {
return false;
}
}
return true;
}