File tree Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Expand file tree Collapse file tree 2 files changed +30
-7
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,18 @@ func ReadFile(path string) (urls []string, err error) {
3333 if err != nil {
3434 return lins , err // error or EOF
3535 }
36- str = str [:len (str )- 2 ]
36+ // 如果是空行,则跳过
37+ if strings .TrimSpace (str ) == "" {
38+ continue
39+ }
40+ // 如果str结尾存在\r\n,则去掉
41+ if strings .HasSuffix (str , "\r " ) {
42+ str = strings .TrimSuffix (str , "\r \n " )
43+ }
44+ // 如果str结尾存在\n,则去掉
45+ if strings .HasSuffix (str , "\n " ) {
46+ str = strings .TrimSuffix (str , "\n " )
47+ }
3748 log .Debugf ("The url is : " , str )
3849 lins = append (lins , str )
3950 }
Original file line number Diff line number Diff line change 11package main
22
3- import "github.com/projectdiscovery/mapcidr"
3+ import (
4+ "strings"
5+ )
46
57func main () {
6- ip := "192.168.1.2/32"
7- subnets , _ := mapcidr .IPAddresses (ip )
8-
9- for _ , subnet := range subnets {
10- println ("http://" + subnet )
8+ str := "http://example.com/\r \n "
9+ u1 := "http://example.com\n "
10+ u2 := "http://example.com\r "
11+ //如果字符串存在\r或者\n,那么去掉这个\r或者\n
12+ // 如果str结尾存在\r\n,则去掉
13+ if strings .HasSuffix (str , "\r " ) {
14+ str = strings .TrimSuffix (str , "\r \n " )
15+ }
16+ // 如果str结尾存在\n,则去掉
17+ if strings .HasSuffix (str , "\n " ) {
18+ str = strings .TrimSuffix (str , "\n " )
1119 }
20+ println (str )
21+
22+ println (u1 )
23+ println (u2 )
1224}
You can’t perform that action at this time.
0 commit comments