Skip to content

Commit

Permalink
Fix RegexpError when parsing command.
Browse files Browse the repository at this point in the history
  • Loading branch information
kuboshizuma committed Nov 26, 2015
1 parent bb1d494 commit 58f6300
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
9 changes: 7 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This configuration was generated by `rubocop --auto-gen-config`
# on 2015-11-20 10:29:04 -0700 using RuboCop version 0.32.1.
# on 2015-11-26 14:43:46 +0900 using RuboCop version 0.32.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -17,11 +17,16 @@ Lint/UselessAccessModifier:
Metrics/AbcSize:
Max: 27

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 101

# Offense count: 3
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 94
# Offense count: 96
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 145
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix: explicitly require 'giphy' - [@dblock](https://github.com/dblock).
* Fix: undefined method `stop` for `Slack::RealTime::Client` - [@dblock](https://github.com/dblock).
* [#29](https://github.com/dblock/slack-ruby-bot/pull/29): Fixed bot failing to correctly respond to unknown commands when queried with format `@botname` - [@crayment](https://github.com/crayment).
* [#30](https://github.com/dblock/slack-ruby-bot/pull/30): Fix RegexpError when parsing command - [@kuboshizuma](https://github.com/kuboshizuma).
* Your contribution here.

### 0.4.5 (10/29/2015)
Expand Down
5 changes: 3 additions & 2 deletions lib/slack-ruby-bot/commands/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def self.operator(*values, &block)

def self.command(*values, &block)
values.each do |value|
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{value})$", Regexp::IGNORECASE), &block
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{value})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
escaped = Regexp.escape(value)
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{escaped})$", Regexp::IGNORECASE), &block
match Regexp.new("^(?<bot>[\\w[:punct:]@<>]*)[\\s]+(?<command>#{escaped})[\\s]+(?<expression>.*)$", Regexp::IGNORECASE), &block
end
end

Expand Down
17 changes: 17 additions & 0 deletions spec/slack-ruby-bot/commands/commands_regexp_escape_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe SlackRubyBot::Commands do
let! :command do
Class.new(SlackRubyBot::Commands::Base) do
command '(' do |client, data, match|
send_message client, data.channel, "#{match[:command]}: #{match[:expression]}"
end
end
end
def app
SlackRubyBot::App.new
end
it 'does not return error' do
expect(message: "#{SlackRubyBot.config.user} ( /").to respond_with_slack_message('(: /')
end
end

0 comments on commit 58f6300

Please sign in to comment.