File tree Expand file tree Collapse file tree 2 files changed +8
-4
lines changed
Expand file tree Collapse file tree 2 files changed +8
-4
lines changed Original file line number Diff line number Diff line change 1616 profileEnd = regexp .MustCompile (`(?i)# end\s*` )
1717 spaceRemover = regexp .MustCompile (`\s+` )
1818 tabReplacer = regexp .MustCompile (`\t+` )
19+ endingComment = regexp .MustCompile (`(.[^#]*).*` )
1920)
2021
2122// Parser is the interface for content parsers
@@ -142,8 +143,9 @@ func parseRouteLine(str string) (*types.Route, bool) {
142143 clean := spaceRemover .ReplaceAllString (str , " " )
143144 clean = tabReplacer .ReplaceAllString (clean , " " )
144145 clean = strings .TrimSpace (clean )
145-
146- p := strings .Split (clean , " " )
146+ result := endingComment .FindStringSubmatch (clean )
147+ tResult := strings .TrimSpace (result [1 ])
148+ p := strings .Split (tResult , " " )
147149
148150 i := 0
149151 if p [0 ] == "#" && len (p ) > 1 {
Original file line number Diff line number Diff line change @@ -93,7 +93,8 @@ func TestParser(t *testing.T) {
9393 }
9494 appendLine (p , "127.0.0.1 first.loc" )
9595 appendLine (p , "127.0.0.1 second.loc" )
96- assert .Len (t , p .Routes ["127.0.0.1" ].HostNames , 2 )
96+ appendLine (p , "127.0.0.1 third.loc # test comment" )
97+ assert .Len (t , p .Routes ["127.0.0.1" ].HostNames , 3 )
9798 })
9899
99100 t .Run ("appendLine disabled" , func (t * testing.T ) {
@@ -102,7 +103,8 @@ func TestParser(t *testing.T) {
102103 Routes : map [string ]* types.Route {},
103104 }
104105 appendLine (p , "# 127.0.0.1 first.loc" )
105- assert .Len (t , p .Routes ["127.0.0.1" ].HostNames , 1 )
106+ appendLine (p , "# 127.0.0.1 second.loc # test comment" )
107+ assert .Len (t , p .Routes ["127.0.0.1" ].HostNames , 2 )
106108 })
107109
108110 t .Run ("appendLine invalid lines" , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments