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) {
33
33
if err != nil {
34
34
return lins , err // error or EOF
35
35
}
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
+ }
37
48
log .Debugf ("The url is : " , str )
38
49
lins = append (lins , str )
39
50
}
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
- import "github.com/projectdiscovery/mapcidr"
3
+ import (
4
+ "strings"
5
+ )
4
6
5
7
func 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 " )
11
19
}
20
+ println (str )
21
+
22
+ println (u1 )
23
+ println (u2 )
12
24
}
You can’t perform that action at this time.
0 commit comments