From 588301529493d297ac9a8c9c9e7172e691933b37 Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Mon, 21 Jun 2021 00:44:20 +0800 Subject: [PATCH] frontend: change behavior of whois shorten mode --- frontend/dn42.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/frontend/dn42.go b/frontend/dn42.go index bea4bf3..8d5f8c9 100644 --- a/frontend/dn42.go +++ b/frontend/dn42.go @@ -53,7 +53,11 @@ func dn42WhoisFilter(whois string) string { /* experimental, behavior may change */ func shortenWhoisFilter(whois string) string { commandResult := "" + commandResultLonger := "" + lines := 0 + linesLonger := 0 skippedLines := 0 + skippedLinesLonger := 0 for _, s := range strings.Split(whois, "\n") { s = strings.TrimSpace(s) @@ -62,6 +66,15 @@ func shortenWhoisFilter(whois string) string { shouldSkip = shouldSkip || len(s) == 0 shouldSkip = shouldSkip || len(s) > 80 shouldSkip = shouldSkip || len(s) > 0 && s[0] == '#' + + if shouldSkip { + skippedLinesLonger++ + continue + } + + commandResultLonger += s + "\n" + linesLonger++ + shouldSkip = shouldSkip || !strings.Contains(s, ":") shouldSkip = shouldSkip || strings.Index(s, ":") > 20 @@ -71,6 +84,12 @@ func shortenWhoisFilter(whois string) string { } commandResult += s + "\n" + lines++ + } + + if lines < 10 { + commandResult = commandResultLonger + skippedLines = skippedLinesLonger } if skippedLines > 0 {