Skip to content

Commit

Permalink
bot: Limit DELAY_SPEC to 7 digits max.
Browse files Browse the repository at this point in the history
Prevent accidentally sabotage a job that won't run for a week for
example.
  • Loading branch information
chfoo committed Feb 6, 2015
1 parent c91df5d commit ae692d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions bot/command_patterns.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module CommandPatterns
AC = %r{([^\s]+)(?:\s+(.+))?}
IDENT = %r{[0-9a-z]+}
DELAY_SPEC = %r{[\d]+}
DELAY_SPEC = %r{[\d]{1,7}}

ARCHIVE = %r{\A(?:\!a|\!archive|\!firstworldproblems)(?!\s+<)\s+#{AC}\s*\Z}
ARCHIVE_FILE = %r{\A(?:\!a|\!archive|\!firstworldproblems)\s+<\s+#{AC}\s*\Z}
ARCHIVEONLY = %r{\A(?:\!ao|\!archiveonly)(?!\s+<)\s+#{AC}\s*\Z}
ARCHIVEONLY_FILE = %r{\A(?:\!ao|\!archiveonly)\s+<\s+#{AC}\s*\Z}
SET_DELAY = %r{\A\!d(?:elay)?\s+(#{IDENT})\s+(#{DELAY_SPEC})\s+(#{DELAY_SPEC})}
SET_DELAY = %r{\A\!d(?:elay)?\s+(#{IDENT})\s+(#{DELAY_SPEC})\s+(#{DELAY_SPEC})\s*\Z}
SET_CONCURRENCY = %r{\A\!con(?:currency)?\s+(#{IDENT})\s+(\d{1,2})\s*\Z}
IGNORE = %r{\A!ig(?:nore)?\s+(#{IDENT})\s+([^\s]+)\s*\Z}
UNIGNORE = %r{\A!unig(?:nore)?\s+(#{IDENT})\s+([^\s]+)\s*\Z}
Expand Down
6 changes: 6 additions & 0 deletions spec/bot/command_patterns_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@

md.should be_nil
end

it "does not recognize exceedingly large delays" do
md = regex.match "#{cmd} f4pg9usx4j96ki3zczwlczu51 0 10000000"

md.should be_nil
end
end

describe 'Set delay command' do
Expand Down

0 comments on commit ae692d8

Please sign in to comment.