@@ -615,10 +615,22 @@ func importSecurityCSV(r *http.Request) ([][]string, error) {
615615 return records , nil
616616}
617617
618+ // stripInlineComment removes a trailing "#"-style comment from a rule line and
619+ // trims the remainder. The marker only counts at the start of the line or when
620+ // preceded by whitespace, so a "#" embedded mid-token is left alone.
621+ func stripInlineComment (line string ) string {
622+ for i := 0 ; i < len (line ); i ++ {
623+ if line [i ] == '#' && (i == 0 || line [i - 1 ] == ' ' || line [i - 1 ] == '\t' ) {
624+ return strings .TrimSpace (line [:i ])
625+ }
626+ }
627+ return line
628+ }
629+
618630func parseIPRules (raw string , listType int ) []db.IPRule {
619631 var out []db.IPRule
620632 for _ , line := range strings .Split (raw , "\n " ) {
621- line = strings .TrimSpace (line )
633+ line = stripInlineComment ( strings .TrimSpace (line ) )
622634 if line == "" || strings .HasPrefix (line , "#" ) {
623635 continue
624636 }
@@ -630,7 +642,7 @@ func parseIPRules(raw string, listType int) []db.IPRule {
630642func parseUARules (raw string , listType int ) []db.UARule {
631643 var out []db.UARule
632644 for _ , line := range strings .Split (raw , "\n " ) {
633- line = strings .TrimSpace (line )
645+ line = stripInlineComment ( strings .TrimSpace (line ) )
634646 if line == "" || strings .HasPrefix (line , "#" ) {
635647 continue
636648 }
@@ -645,7 +657,7 @@ func parseUARules(raw string, listType int) []db.UARule {
645657func parseCountryRules (raw string , listType int ) []db.CountryRule {
646658 var out []db.CountryRule
647659 for _ , line := range strings .Split (raw , "\n " ) {
648- line = strings .ToUpper (strings .TrimSpace (line ))
660+ line = strings .ToUpper (stripInlineComment ( strings .TrimSpace (line ) ))
649661 if line == "" || strings .HasPrefix (line , "#" ) {
650662 continue
651663 }
@@ -752,7 +764,7 @@ func (h *Handler) saveASNRules(w http.ResponseWriter, r *http.Request, siteID *i
752764func parseASNRules (raw string , listType int ) []db.ASNRule {
753765 var out []db.ASNRule
754766 for _ , line := range strings .Split (raw , "\n " ) {
755- line = strings .ToUpper (strings .TrimSpace (line ))
767+ line = strings .ToUpper (stripInlineComment ( strings .TrimSpace (line ) ))
756768 if line == "" || strings .HasPrefix (line , "#" ) {
757769 continue
758770 }
0 commit comments