fix the bug of region filtering

This commit is contained in:
lion 2025-09-12 09:44:34 +08:00
parent 4911bdcd41
commit c6c0ee954f
3 changed files with 9 additions and 2 deletions

View File

@ -178,6 +178,10 @@ public class Maker {
// apply the field filtering // apply the field filtering
final String region = Util.regionFiltering(seg.region, fields); final String region = Util.regionFiltering(seg.region, fields);
if (region.length() < 1) {
throw new Exception("empty region info for segment `"+seg+"`");
}
segments.add(new Segment(seg.startIP, seg.endIP, region)); segments.add(new Segment(seg.startIP, seg.endIP, region));
last = seg; last = seg;
} }

View File

@ -118,7 +118,7 @@ public class Util
} }
sb.append(fs[idx]); sb.append(fs[idx]);
if (sb.length() > 0 && i < tailing) { if (i < tailing) {
sb.append("|"); sb.append("|");
} }
} }

View File

@ -80,7 +80,10 @@ public class UtilTest {
public void testRegionFiltering() { public void testRegionFiltering() {
final String[] regions = new String[]{ final String[] regions = new String[]{
"亚洲|中国|广东|深圳|宝安|电信|113.88311|22.55371|440306|0755|518100|Asia/Shanghai|CNY|11|CHXX0120", "亚洲|中国|广东|深圳|宝安|电信|113.88311|22.55371|440306|0755|518100|Asia/Shanghai|CNY|11|CHXX0120",
"大洲|国家|省份|城市|区县|ISP|经度|纬度|0|0|0|0|0" "大洲|国家|省份|城市|区县|ISP|经度|纬度|0|0|0|0|0",
"||||||||||||",
"亚洲|中国|||||||||||",
"美国|加利福尼亚州|洛杉矶|专线用户|||||||||"
}; };
final int[] fields = new int[] {1,2,3,4,6,7}; final int[] fields = new int[] {1,2,3,4,6,7};