Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Not every rule has options

  • Loading branch information...
commit 24daa4e0e8b348be127baa875e0f42fc14cfc140 1 parent 5cafe81
Jeremy McAnally authored
Showing with 15 additions and 10 deletions.
  1. +15 −10 lib/snort/rule.rb
25 lib/snort/rule.rb
View
@@ -23,15 +23,20 @@ def initialize(kwargs={})
# Output the current object into a snort rule
def to_s(options_only=false)
rule = ""
- rule = [@action, @proto, @src, @sport, @dir, @dst, @dport, '( '].join(" ") unless options_only
- opts.keys.sort.each do |k|
- rule += k if opts[k];
- unless opts[k] == true
- rule += ":#{opts[k]}"
- end
- rule += "; "
- end
- rule += ")" unless options_only
+ rule = [@action, @proto, @src, @sport, @dir, @dst, @dport].join(" ") unless options_only
+
+ if opts
+ rule += "(" unless options_only
+ opts.keys.sort.each do |k|
+ rule += k if opts[k];
+ unless opts[k] == true
+ rule += ":#{opts[k]}"
+ end
+ rule += "; "
+ end
+ rule += ")" unless options_only
+ end
+
rule
end
@@ -46,7 +51,7 @@ def Rule::parse(string)
else
[x,true]
end
- }]
+ }] if optspart
rule
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.