bypass 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.travis.yml +0 -2
- data/README.md +2 -0
- data/bypass.gemspec +4 -3
- data/lib/bypass/filter.rb +4 -3
- data/lib/bypass/html_filter.rb +11 -1
- data/lib/bypass/version.rb +1 -1
- data/test/bypass/filter_test.rb +1 -1
- data/test/bypass/html_filter_test.rb +32 -1
- data/test/bypass/text_filter_test.rb +1 -1
- data/test/bypass/uri_test.rb +1 -1
- metadata +24 -10
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NDg3NGIwZGM4MzZjMDJiMjJhNmU0MGYzMWVhNmJmYmJlNWVjY2EyZA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 718e8ae5c353526d782ccaa70459e5f5dc70b84f
|
4
|
+
data.tar.gz: 870eadce1dfe1ba0fe41625d12527fe3fa09c03b
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZTNiMmYwOTE2MDY3NTg3MGRiMmUxYTgxNDFhMjVkNjQ4ZTllMGYyZTI2NGQ5
|
11
|
-
YmU5ODQ2YzNjMzBmZjUxMTMwMzUxM2QyNWQ4MjY3ZDEwYzIxMzk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ODYyMDZiODQ3ZjZhOGQxNmIyZGJkNGVmMzBjNWE1NDdhZTU2N2FjODAxODI2
|
14
|
-
ZjE1MTI2NGY0ODc2ZmM1NTc1NmQ2NTk3NDhjMDU3NDE0ZThlOTlkMjMwNjU2
|
15
|
-
YTM1MjNjM2I5NzFiYjgxZWJjZjUzNjA3YmUzNWEyNTMzMGNkNmU=
|
6
|
+
metadata.gz: 6a11749670fe237ebe686e126a9620ed2463c9855284290850c9ca81cf85d14f7c5e679b70543006986ec668d18538ced58ec7e21b889dad8ec79bf43aa02a55
|
7
|
+
data.tar.gz: a2d4dfcd1fc1ff96b30452dc251bfff9a1826fd6de7e860016a2ff00cc1584ba43d6ad33232b23d867f4850fd6b9f2eef6200bae7b6d16af3ddfdadfef42f66e
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,7 @@ filter = Bypass::TextFilter.new(text)
|
|
38
38
|
|
39
39
|
filter.replace do |url|
|
40
40
|
url.append_to_query_values(:id => 123)
|
41
|
+
url
|
41
42
|
end
|
42
43
|
|
43
44
|
filter.content
|
@@ -54,6 +55,7 @@ filter = Bypass::HTMLFilter.new(text)
|
|
54
55
|
|
55
56
|
filter.replace do |url|
|
56
57
|
url.append_to_query_values(:id => 123)
|
58
|
+
url
|
57
59
|
end
|
58
60
|
|
59
61
|
filter.content
|
data/bypass.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Bypass::VERSION
|
9
9
|
gem.authors = ["Derrick Reimer"]
|
10
10
|
gem.email = ["derrickreimer@gmail.com"]
|
11
|
-
gem.description =
|
12
|
-
gem.summary =
|
11
|
+
gem.description = "Mutate URLs and hyperlinks in HTML and plain text documents"
|
12
|
+
gem.summary = "Mutate URLs and hyperlinks in HTML and plain text documents with ease"
|
13
13
|
gem.homepage = "https://github.com/djreimer/bypass"
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
|
20
20
|
gem.add_dependency "nokogiri", "~> 1.5"
|
21
21
|
gem.add_dependency "addressable", "~> 2.0"
|
22
|
-
gem.add_development_dependency "
|
22
|
+
gem.add_development_dependency "minitest", "~> 5.0"
|
23
|
+
gem.add_development_dependency "shoulda-context", "~> 1.2"
|
23
24
|
gem.add_development_dependency "mocha"
|
24
25
|
end
|
data/lib/bypass/filter.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
module Bypass
|
2
2
|
class Filter
|
3
|
-
attr_reader :content
|
3
|
+
attr_reader :content, :fragment
|
4
4
|
|
5
5
|
URL_PATTERN = /\bhttps?:\/\/
|
6
6
|
[a-zA-Z0-9\-\._~:\/\?#\[\]@!$&'\(\)\*\+,;=%]+
|
7
7
|
[a-zA-Z0-9\-_~:\/\?#\[\]@!$&\*\+;=%]/x
|
8
8
|
|
9
|
-
def initialize(content)
|
10
|
-
@content = content.to_s
|
9
|
+
def initialize(content, options = {})
|
10
|
+
@content = content.to_s.encode("UTF-8")
|
11
|
+
@fragment = options.fetch(:fragment, true)
|
11
12
|
end
|
12
13
|
|
13
14
|
def replace
|
data/lib/bypass/html_filter.rb
CHANGED
@@ -46,11 +46,21 @@ module Bypass
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def parsed_content
|
49
|
-
@parsed_content ||=
|
49
|
+
@parsed_content ||= begin
|
50
|
+
if fragment
|
51
|
+
parse_html_fragment(@content)
|
52
|
+
else
|
53
|
+
parse_html_document(@content)
|
54
|
+
end
|
55
|
+
end
|
50
56
|
end
|
51
57
|
|
52
58
|
def parse_html_fragment(html)
|
53
59
|
Nokogiri::HTML::DocumentFragment.parse(html)
|
54
60
|
end
|
61
|
+
|
62
|
+
def parse_html_document(html)
|
63
|
+
Nokogiri::HTML::Document.parse(html)
|
64
|
+
end
|
55
65
|
end
|
56
66
|
end
|
data/lib/bypass/version.rb
CHANGED
data/test/bypass/filter_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'addressable/uri'
|
2
2
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
3
3
|
|
4
|
-
class Bypass::HTMLFilterTest < Test
|
4
|
+
class Bypass::HTMLFilterTest < MiniTest::Test
|
5
5
|
context "#replace" do
|
6
6
|
should "replace hrefs" do
|
7
7
|
text = "<a href=\"http://yahoo.com\">Yahoo</a>"
|
@@ -72,5 +72,36 @@ class Bypass::HTMLFilterTest < Test::Unit::TestCase
|
|
72
72
|
filter.expects(:parsed_content).returns(stub(:to_s => "bar"))
|
73
73
|
assert_equal "bar", filter.content
|
74
74
|
end
|
75
|
+
|
76
|
+
should "handle document fragments" do
|
77
|
+
filter = Bypass::HTMLFilter.new("<div>text</div>")
|
78
|
+
assert_equal "<div>text</div>", filter.content
|
79
|
+
end
|
80
|
+
|
81
|
+
should "handle whole documents" do
|
82
|
+
lines = []
|
83
|
+
|
84
|
+
lines << "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">"
|
85
|
+
lines << "<html>"
|
86
|
+
lines << " <head></head>"
|
87
|
+
lines << " <body>"
|
88
|
+
lines << " <div>Content</div>"
|
89
|
+
lines << " </body>"
|
90
|
+
lines << "</html>"
|
91
|
+
|
92
|
+
document = lines.join("\n")
|
93
|
+
expected = document.sub("<head></head>", "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"></head>")
|
94
|
+
|
95
|
+
filter = Bypass::HTMLFilter.new(document, :fragment => false)
|
96
|
+
assert_normalized_equal expected, filter.content
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def assert_normalized_equal(expected, actual)
|
101
|
+
assert_equal normalize_output(expected), normalize_output(actual)
|
102
|
+
end
|
103
|
+
|
104
|
+
def normalize_output(html)
|
105
|
+
html.lines.map(&:strip).join("")
|
75
106
|
end
|
76
107
|
end
|
data/test/bypass/uri_test.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../test_helper.rb'
|
2
2
|
|
3
|
-
class Bypass::URITest < Test
|
3
|
+
class Bypass::URITest < MiniTest::Test
|
4
4
|
context "#append_to_query_values" do
|
5
5
|
should "add values to the query string if it starts empty" do
|
6
6
|
uri = Bypass::URI.parse("http://www.getdrip.com")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bypass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derrick Reimer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -38,35 +38,49 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: shoulda-context
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ~>
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
61
|
+
version: '1.2'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - ~>
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '1.
|
68
|
+
version: '1.2'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: mocha
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
|
-
- -
|
73
|
+
- - '>='
|
60
74
|
- !ruby/object:Gem::Version
|
61
75
|
version: '0'
|
62
76
|
type: :development
|
63
77
|
prerelease: false
|
64
78
|
version_requirements: !ruby/object:Gem::Requirement
|
65
79
|
requirements:
|
66
|
-
- -
|
80
|
+
- - '>='
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '0'
|
69
|
-
description: Mutate URLs and hyperlinks in HTML and plain text documents
|
83
|
+
description: Mutate URLs and hyperlinks in HTML and plain text documents
|
70
84
|
email:
|
71
85
|
- derrickreimer@gmail.com
|
72
86
|
executables: []
|
@@ -100,17 +114,17 @@ require_paths:
|
|
100
114
|
- lib
|
101
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
116
|
requirements:
|
103
|
-
- -
|
117
|
+
- - '>='
|
104
118
|
- !ruby/object:Gem::Version
|
105
119
|
version: '0'
|
106
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
121
|
requirements:
|
108
|
-
- -
|
122
|
+
- - '>='
|
109
123
|
- !ruby/object:Gem::Version
|
110
124
|
version: '0'
|
111
125
|
requirements: []
|
112
126
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.3.0
|
114
128
|
signing_key:
|
115
129
|
specification_version: 4
|
116
130
|
summary: Mutate URLs and hyperlinks in HTML and plain text documents with ease
|