Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RegexpError when parsing command #30

Merged
merged 1 commit into from
Nov 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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