diff --git a/lib/zero/router.rb b/lib/zero/router.rb index 482f25a..7f16933 100644 --- a/lib/zero/router.rb +++ b/lib/zero/router.rb @@ -20,7 +20,7 @@ module Zero # match for variables in routes VARIABLE_MATCH = %r{:(\w+)[^/]?} # the replacement string to make it an regex - VARIABLE_REGEX = '(?<\1>[\w]+?)' + VARIABLE_REGEX = '(?<\1>[\w-]+?)' # regex part of the beginning of the line REGEX_BEGINNING = '\A' # regex part of the end of the line diff --git a/spec/unit/zero/router/call_spec.rb b/spec/unit/zero/router/call_spec.rb index 923b747..835d51d 100644 --- a/spec/unit/zero/router/call_spec.rb +++ b/spec/unit/zero/router/call_spec.rb @@ -103,4 +103,17 @@ describe Zero::Router, '#call' do it_behaves_like "a sample app" end + + context 'with a dash in the variable' do + let(:routes) { {'/:id' => app} } + let(:env) { EnvGenerator.get('/foo-bar') } + let(:app) do + lambda do |env| + [200, content_type, [Zero::Request.new(env).params['id']]] + end + end + let(:result) { ['foo-bar'] } + + it_behaves_like "a sample app" + end end