fixed region fetching in user_attributes

This commit is contained in:
2026-03-24 16:38:41 +08:00
parent 7847206283
commit f0bc603a5f
3 changed files with 70 additions and 29 deletions
+33
View File
@@ -60,9 +60,17 @@ func compare(actual, expected, operator string) bool {
switch operator {
case "=":
// Special logic for region: allow '1' and '01' to match
if isRegionComparison(actual, expected) {
return normalizeRegion(actual) == normalizeRegion(expected)
}
return actual == expected // case-sensitive
case "!=":
// Special logic for region: allow '1' and '01' to match
if isRegionComparison(actual, expected) {
return normalizeRegion(actual) != normalizeRegion(expected)
}
return actual != expected // case-sensitive
case ">":
@@ -94,6 +102,31 @@ func compare(actual, expected, operator string) bool {
}
}
// Checks if the comparison is for region attribute
func isRegionComparison(actual, expected string) bool {
// Only trigger for region values that are numeric or zero-padded numeric
// This is a heuristic: if both are digits or zero-padded digits, treat as region
return isRegionValue(actual) && isRegionValue(expected)
}
func isRegionValue(val string) bool {
val = strings.TrimLeft(val, "0")
return len(val) > 0 && isDigits(val)
}
func isDigits(val string) bool {
for _, r := range val {
if r < '0' || r > '9' {
return false
}
}
return true
}
func normalizeRegion(val string) string {
return strings.TrimLeft(val, "0")
}
func numericCompare(actual, expected string, compareFn func(float64, float64) bool) bool {
actualNum, err1 := strconv.ParseFloat(actual, 64)
expectedNum, err2 := strconv.ParseFloat(expected, 64)