mustermann 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mustermann/error.rb +6 -4
- data/lib/mustermann/regular.rb +6 -1
- data/lib/mustermann/version.rb +1 -1
- data/mustermann.gemspec +2 -2
- data/spec/regular_spec.rb +17 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c1952019b943fa6b499465e215a4b7ba68c3cbd
|
4
|
+
data.tar.gz: e390428040cf68a16dea8367d87417bf921bd0c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6abd1d958db391ebea46b12e16f151473a73f25eb684614fc2a87f8f0b72c7facf344b0b0ce0ee1feb58d3397f816b41b217d654cb5d537b02cb9c20404b662
|
7
|
+
data.tar.gz: '09be3f684228b37319fd48eff0d119350a71f9d1d558b89266b78a9cd0510dd9852c4454e0e3b4fda5e848dd3190208795f3b8c2e489c3962e2987f9fd615d7e'
|
data/lib/mustermann/error.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
module Mustermann
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
unless defined?(Mustermann::Error)
|
4
|
+
Error = Class.new(StandardError) # Raised if anything goes wrong while generating a {Pattern}.
|
5
|
+
CompileError = Class.new(Error) # Raised if anything goes wrong while compiling a {Pattern}.
|
6
|
+
ParseError = Class.new(Error) # Raised if anything goes wrong while parsing a {Pattern}.
|
7
|
+
ExpandError = Class.new(Error) # Raised if anything goes wrong while expanding a {Pattern}.
|
8
|
+
end
|
7
9
|
end
|
data/lib/mustermann/regular.rb
CHANGED
@@ -21,6 +21,7 @@ module Mustermann
|
|
21
21
|
# @see (see Mustermann::Pattern#initialize)
|
22
22
|
def initialize(string, check_anchors: true, **options)
|
23
23
|
string = $1 if string.to_s =~ /\A\(\?\-mix\:(.*)\)\Z/ && string.inspect == "/#$1/"
|
24
|
+
string = string.source.gsub!(/(?<!\\)(?:\s|#.*$)/, '') if extended_regexp?(string)
|
24
25
|
@check_anchors = check_anchors
|
25
26
|
super(string, **options)
|
26
27
|
end
|
@@ -40,6 +41,10 @@ module Mustermann
|
|
40
41
|
raise CompileError, "regular expression should not contain %s: %p" % [illegal.to_s, @string]
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
+
def extended_regexp?(string)
|
45
|
+
not (Regexp.new(string).options & Regexp::EXTENDED).zero?
|
46
|
+
end
|
47
|
+
|
48
|
+
private :compile, :check_anchors, :extended_regexp?
|
44
49
|
end
|
45
50
|
end
|
data/lib/mustermann/version.rb
CHANGED
data/mustermann.gemspec
CHANGED
@@ -7,8 +7,8 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.authors = ["Konstantin Haase", "Zachary Scott"]
|
8
8
|
s.email = "sinatrarb@googlegroups.com"
|
9
9
|
s.homepage = "https://github.com/sinatra/mustermann"
|
10
|
-
s.summary = %q{
|
11
|
-
s.description = %q{library implementing patterns that behave like regular expressions}
|
10
|
+
s.summary = %q{Your personal string matching expert.}
|
11
|
+
s.description = %q{A library implementing patterns that behave like regular expressions.}
|
12
12
|
s.license = 'MIT'
|
13
13
|
s.required_ruby_version = '>= 2.2.0'
|
14
14
|
s.files = `git ls-files`.split("\n")
|
data/spec/regular_spec.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
require 'support'
|
3
|
+
require 'timeout'
|
3
4
|
require 'mustermann/regular'
|
4
5
|
|
5
6
|
describe Mustermann::Regular do
|
@@ -38,6 +39,22 @@ describe Mustermann::Regular do
|
|
38
39
|
it { should match('/foo%2Fbar') .capturing foo: 'foo%2Fbar' }
|
39
40
|
end
|
40
41
|
|
42
|
+
|
43
|
+
context 'with Regexp::EXTENDED' do
|
44
|
+
let(:pattern) {
|
45
|
+
%r{
|
46
|
+
\/compare\/ # match any URL beginning with \/compare\/
|
47
|
+
(.+) # extract the full path (including any directories)
|
48
|
+
\/ # match the final slash
|
49
|
+
([^.]+) # match the first SHA1
|
50
|
+
\.{2,3} # match .. or ...
|
51
|
+
(.+) # match the second SHA1
|
52
|
+
}x
|
53
|
+
}
|
54
|
+
example { expect { Timeout.timeout(1){ Mustermann::Regular.new(pattern) }}.not_to raise_error(Timeout::Error) }
|
55
|
+
it { expect(Mustermann::Regular.new(pattern)).to match('/compare/foo/bar..baz') }
|
56
|
+
end
|
57
|
+
|
41
58
|
describe :check_achnors do
|
42
59
|
context 'raises on anchors' do
|
43
60
|
example { expect { Mustermann::Regular.new('^foo') }.to raise_error(Mustermann::CompileError) }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mustermann
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Konstantin Haase
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-08-26 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: library implementing patterns that behave like regular expressions
|
14
|
+
description: A library implementing patterns that behave like regular expressions.
|
15
15
|
email: sinatrarb@googlegroups.com
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
@@ -92,8 +92,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
95
|
+
rubygems_version: 2.6.11
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
|
-
summary:
|
98
|
+
summary: Your personal string matching expert.
|
99
99
|
test_files: []
|