urlmatch 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/Gemfile +5 -0
- data/LICENSE +7 -0
- data/README.md +46 -0
- data/Rakefile +6 -0
- data/lib/urlmatch.rb +34 -0
- data/urlmatch.gemspec +24 -0
- metadata +94 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 4962e68e0fb5777dfe9e1053c07647d8b174da91
|
|
4
|
+
data.tar.gz: d5922da758013b3bb69fa7b218f9c02afb7fbe19
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 62342a3505d4e5af548ef76581267e795324c76de9835ab96986b69990c47767b2b7067ab226fa82fc82b6751a65d5053c4e1fe466fef32b9f9e7f475986114a
|
|
7
|
+
data.tar.gz: d08ab515dbea64b8c1cf9c1fcc83c3a82897da0647bb75af04acdec1adb58b62b55d47907df2c38d6d076b487e075d0f9299d089ba8affd514dc4c7ec9d36239
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2017 Onfido
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
data/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
urlmatch - fnmatch for the web
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
This is a Ruby port of Jesse Pollak's Python [urlmatch](https://github.com/jessepollak/urlmatch).
|
|
5
|
+
|
|
6
|
+
Use `urlmatch` to verify that URLs conform to certain patterns. The library and match patterns are based heavily on the [Google Chrome Extension match patterns](http://developer.chrome.com/extensions/match_patterns).
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
require 'urlmatch'
|
|
12
|
+
|
|
13
|
+
match_pattern = 'http://*.example.com/*'
|
|
14
|
+
|
|
15
|
+
Urlmatch.urlmatch(match_pattern, 'http://subdomain.example.com/') # true
|
|
16
|
+
Urlmatch.urlmatch(match_pattern, 'http://sub.subdomain.example.com/') # true
|
|
17
|
+
|
|
18
|
+
Urlmatch.urlmatch(match_pattern, 'https://example.com/') # false
|
|
19
|
+
Urlmatch.urlmatch(match_pattern, 'http://bad.com/') # false
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Match pattern syntax
|
|
23
|
+
|
|
24
|
+
The basic match pattern syntax is simple:
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
<url-pattern> := <scheme>://<host><path>
|
|
28
|
+
<scheme> := '*' | 'http' | 'https'
|
|
29
|
+
<host> := '*' | '*.' <any char except '/' and '*'>+
|
|
30
|
+
<path> := '/' <any chars>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Examples
|
|
34
|
+
|
|
35
|
+
* `http://*/*` - matches any URL that uses the http scheme
|
|
36
|
+
* `https://*/*` - matches any URL that uses the https scheme
|
|
37
|
+
* `http://*/test*` - matches any URL that uses the http scheme and has a path that starts with `test`
|
|
38
|
+
* `*://test.com/*` - matches any url with the domain `test.com`
|
|
39
|
+
* `http://*.test.com` - matches `test.com` and any subdomain of `test.com`
|
|
40
|
+
* `http://test.com/foo/bar.html` - matches the exact URL
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Bugs
|
|
44
|
+
----
|
|
45
|
+
|
|
46
|
+
If you find an issue, let me know in the issues section!
|
data/Rakefile
ADDED
data/lib/urlmatch.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Urlmatch
|
|
2
|
+
class Error < StandardError
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def self.urlmatch(pattern, url)
|
|
7
|
+
# (scheme)://(domain)/(path)
|
|
8
|
+
regex = /\A(\*|https|http):\/\/(\*|\*\.[^\*\/]+|[^\*\/]+)\/(.*)\z/
|
|
9
|
+
@@pattern_match = regex.match(pattern)
|
|
10
|
+
raise Error, "Invalid Match Pattern: #{pattern}" unless @@pattern_match
|
|
11
|
+
url_regex = /\A#{scheme}:\/\/#{domain}\/#{path}\z/
|
|
12
|
+
!!url_regex.match(url)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def self.scheme
|
|
18
|
+
scheme_pattern = @@pattern_match[1]
|
|
19
|
+
scheme_pattern == '*' ? /https?/ : scheme_pattern
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.domain
|
|
23
|
+
domain_pattern = @@pattern_match[2]
|
|
24
|
+
return (/#{Regexp.quote(domain_pattern)}/) unless domain_pattern.start_with?('*')
|
|
25
|
+
return (/[^\/]+/) if domain_pattern == '*'
|
|
26
|
+
non_wild_domain = domain_pattern[2..-1]
|
|
27
|
+
/([^\/]+\.)?#{Regexp.quote(non_wild_domain)}/
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.path
|
|
31
|
+
path_pattern = @@pattern_match[3]
|
|
32
|
+
path_pattern.sub('*', '.*')
|
|
33
|
+
end
|
|
34
|
+
end
|
data/urlmatch.gemspec
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |s|
|
|
5
|
+
s.author = 'Henry heath'
|
|
6
|
+
s.email = 'henry.heath@onfido.com'
|
|
7
|
+
s.name = 'urlmatch'
|
|
8
|
+
s.version = '0.1.1'
|
|
9
|
+
s.summary = "fnmatch for the web"
|
|
10
|
+
s.description = "Verify URLs confirm to expected patterns. Ruby port of Jesse Pollak's Urlmatch"
|
|
11
|
+
|
|
12
|
+
s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
13
|
+
s.require_paths = ["lib"]
|
|
14
|
+
|
|
15
|
+
s.license = 'Apache'
|
|
16
|
+
s.homepage = 'https://github.com/hjheath/ruby_urlmatch'
|
|
17
|
+
|
|
18
|
+
s.add_development_dependency "bundler", "~> 1.11"
|
|
19
|
+
s.add_development_dependency "rake", "~> 10.0"
|
|
20
|
+
s.add_development_dependency "rspec", "~> 3.0"
|
|
21
|
+
|
|
22
|
+
# This is due to Ruby 2.0 keyword arguments.
|
|
23
|
+
s.required_ruby_version = '>= 2.0'
|
|
24
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: urlmatch
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Henry heath
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.11'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.11'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rspec
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '3.0'
|
|
55
|
+
description: Verify URLs confirm to expected patterns. Ruby port of Jesse Pollak's
|
|
56
|
+
Urlmatch
|
|
57
|
+
email: henry.heath@onfido.com
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".gitignore"
|
|
63
|
+
- ".rspec"
|
|
64
|
+
- Gemfile
|
|
65
|
+
- LICENSE
|
|
66
|
+
- README.md
|
|
67
|
+
- Rakefile
|
|
68
|
+
- lib/urlmatch.rb
|
|
69
|
+
- urlmatch.gemspec
|
|
70
|
+
homepage: https://github.com/hjheath/ruby_urlmatch
|
|
71
|
+
licenses:
|
|
72
|
+
- Apache
|
|
73
|
+
metadata: {}
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
require_paths:
|
|
77
|
+
- lib
|
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '2.0'
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
requirements: []
|
|
89
|
+
rubyforge_project:
|
|
90
|
+
rubygems_version: 2.4.6
|
|
91
|
+
signing_key:
|
|
92
|
+
specification_version: 4
|
|
93
|
+
summary: fnmatch for the web
|
|
94
|
+
test_files: []
|