roadie 3.0.4 → 3.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5824c94736e27c2a19d255fe99c7083ad42772b7
4
- data.tar.gz: 0c8a41f35860a127e707f6fa115bb15399dbed8d
3
+ metadata.gz: 149e5b897cfd1808633c9b03e3e4b35fc08f23d4
4
+ data.tar.gz: 1bc5e6e5526f128be884f85a06923f2fbf50ce30
5
5
  SHA512:
6
- metadata.gz: 031ee1cede388f42a4bfbb05ecddcfaf7d42867e28f9e1f08e5645a6fc24efe5dc0a113553ceb6c987eb844ff1fc53e2814eb656ad9ea03709f68662d4f8dc2a
7
- data.tar.gz: 290f00e6c0be0773af92d676ec8e7fa4524ecdad17c688ed5fbddc5afd88a7425779cf589f51822270ebc9f6936cf20f417fc2ff79b0aa0b625db63297959488
6
+ metadata.gz: e3f0f67f6b32561f32b021f09d374b07bb75a7d1e644b0d04e551ba89a135725019c4347b3a2fcf32941a5a15b2b8941dd11dde706d636da567727cab8b69683
7
+ data.tar.gz: ff65e28f825d90b61959eab22e916046835efe6305b37af0d19a7526dfd760ec59a767d28517dda26883f5572866e67e431f2f3fe35f0cb9db9c67add5da9b0a
@@ -1,9 +1,17 @@
1
1
  ### dev
2
2
 
3
- [full changelog](https://github.com/Mange/roadie/compare/v3.0.4...master)
3
+ [full changelog](https://github.com/Mange/roadie/compare/v3.0.5...master)
4
4
 
5
5
  * Nothing yet.
6
6
 
7
+ ### 3.0.5
8
+
9
+ [full changelog](https://github.com/Mange/roadie/compare/v3.0.4...v3.0.5)
10
+
11
+ * Bug fixes:
12
+ * Don't try to inline external stylesheets. (#106)
13
+ * Don't generate absolute URLs for anchor links. (Mange/roadie-rails#40)
14
+
7
15
  ### 3.0.4
8
16
 
9
17
  [full changelog](https://github.com/Mange/roadie/compare/v3.0.3...v3.0.4)
data/README.md CHANGED
@@ -311,7 +311,7 @@ License
311
311
 
312
312
  (The MIT License)
313
313
 
314
- Copyright (c) 2009-2014
314
+ Copyright (c) 2009-2015
315
315
 
316
316
  * [Magnus Bergmark](https://github.com/Mange) <magnus.bergmark@gmail.com>
317
317
 
@@ -4,6 +4,8 @@ end
4
4
  require 'roadie/version'
5
5
  require 'roadie/errors'
6
6
 
7
+ require 'roadie/utils'
8
+
7
9
  require 'roadie/stylesheet'
8
10
  require 'roadie/selector'
9
11
  require 'roadie/style_property'
@@ -80,7 +80,7 @@ module Roadie
80
80
  end
81
81
 
82
82
  def read_link_element(element)
83
- if element['media'] != "print" && element["href"]
83
+ if element['media'] != "print" && element["href"] && !Utils.path_is_absolute?(element["href"])
84
84
  asset_provider.find_stylesheet! element['href']
85
85
  end
86
86
  end
@@ -32,7 +32,8 @@ module Roadie
32
32
 
33
33
  # Generate an absolute URL from a relative URL.
34
34
  #
35
- # If the passed path is already an absolute URL, it will be returned as-is.
35
+ # If the passed path is already an absolute URL or just an anchor
36
+ # reference, it will be returned as-is.
36
37
  # If passed a blank path, the "root URL" will be returned. The root URL is
37
38
  # the URL that the {#url_options} would generate by themselves.
38
39
  #
@@ -56,8 +57,9 @@ module Roadie
56
57
  # @return [String] an absolute URL
57
58
  def generate_url(path, base = "/")
58
59
  return root_uri.to_s if path.nil? or path.empty?
60
+ return path if path_is_anchor?(path)
59
61
  return add_scheme(path) if path_is_schemeless?(path)
60
- return path if path_is_absolute?(path)
62
+ return path if Utils.path_is_absolute?(path)
61
63
 
62
64
  combine_segments(root_uri, base, path).to_s
63
65
  end
@@ -113,20 +115,8 @@ module Roadie
113
115
  path =~ %r{^//\w}
114
116
  end
115
117
 
116
- def path_is_absolute?(path)
117
- # Ruby's URI is pretty unforgiving, but roadie aims to be. Don't involve
118
- # URI for URLs that's easy to determine to be absolute.
119
- # URLs starting with a scheme (http:, data:) are absolute.
120
- #
121
- # URLs that start with double slashes (//css/app.css) are also absolute
122
- # in modern browsers, but most email clients do not understand them it.
123
- path =~ %r{^\w+:} || !parse_path(path).relative?
124
- end
125
-
126
- def parse_path(path)
127
- URI.parse(path)
128
- rescue URI::InvalidURIError => error
129
- raise InvalidUrlPath.new(path, error)
118
+ def path_is_anchor?(path)
119
+ path.start_with? '#'
130
120
  end
131
121
 
132
122
  VALID_OPTIONS = Set[:host, :port, :path, :protocol, :scheme].freeze
@@ -0,0 +1,20 @@
1
+ module Roadie
2
+ module Utils
3
+ def path_is_absolute?(path)
4
+ # Ruby's URI is pretty unforgiving, but roadie aims to be. Don't involve
5
+ # URI for URLs that's easy to determine to be absolute.
6
+ # URLs starting with a scheme (http:, data:) are absolute.
7
+ #
8
+ # URLs that start with double slashes (//css/app.css) are also absolute
9
+ # in modern browsers, but most email clients do not understand them.
10
+ return true if path =~ %r{^(\w+:|//)}
11
+
12
+ begin
13
+ !URI.parse(path).relative?
14
+ rescue URI::InvalidURIError => error
15
+ raise InvalidUrlPath.new(path, error)
16
+ end
17
+ end
18
+ module_function :path_is_absolute?
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module Roadie
2
- VERSION = '3.0.4'
2
+ VERSION = '3.0.5'
3
3
  end
@@ -77,6 +77,15 @@ module Roadie
77
77
  expect(scanner.find_css).to eq([])
78
78
  end
79
79
 
80
+ it "does not look for externally referenced stylesheets" do
81
+ dom = dom_fragment %(<link rel="stylesheet" href="//example.com/assets/style.css">)
82
+ expect(provider).not_to receive(:find_stylesheet!)
83
+
84
+ scanner = AssetScanner.new dom, provider
85
+
86
+ expect(scanner.find_css).to eq([])
87
+ end
88
+
80
89
  it "does not look for ignored referenced stylesheets" do
81
90
  dom = dom_fragment %(<link rel="stylesheet" href="/error.css" data-roadie-ignore>)
82
91
  expect(provider).not_to receive(:find_stylesheet!)
@@ -60,6 +60,10 @@ module Roadie
60
60
  expect(url("http://foo.com/", host: "bar.com")).to eq("http://foo.com/")
61
61
  end
62
62
 
63
+ it "returns the original URL if it is just an anchor" do
64
+ expect(url("#top", host: "bar.com")).to eq("#top")
65
+ end
66
+
63
67
  it "returns the base URL for blank paths" do
64
68
  expect(url("", host: "foo.com")).to eq("http://foo.com")
65
69
  expect(url(nil, host: "foo.com")).to eq("http://foo.com")
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ module Roadie
4
+ describe Utils, "path_is_absolute?" do
5
+ RSpec::Matchers.define :be_absolute do
6
+ match { |path| Utils.path_is_absolute?(path) }
7
+ end
8
+
9
+ it "detects absolute HTTP URLs" do
10
+ expect("http://example.com").to be_absolute
11
+ expect("https://example.com").to be_absolute
12
+ expect("https://example.com/path?foo=bar").to be_absolute
13
+ end
14
+
15
+ it "detects absolute URLs without schemes" do
16
+ expect("//example.com").to be_absolute
17
+ expect("//").to be_absolute
18
+ end
19
+
20
+ it "detects relative URLs without hosts" do
21
+ expect("path/to/me").not_to be_absolute
22
+ expect("/path/to/me").not_to be_absolute
23
+ expect("../../path").not_to be_absolute
24
+ expect("/").not_to be_absolute
25
+ end
26
+ end
27
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roadie
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.4
4
+ version: 3.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Bergmark
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-08 00:00:00.000000000 Z
11
+ date: 2015-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -108,6 +108,7 @@ files:
108
108
  - lib/roadie/upgrade_guide.rb
109
109
  - lib/roadie/url_generator.rb
110
110
  - lib/roadie/url_rewriter.rb
111
+ - lib/roadie/utils.rb
111
112
  - lib/roadie/version.rb
112
113
  - roadie.gemspec
113
114
  - spec/fixtures/big_em.css
@@ -130,6 +131,7 @@ files:
130
131
  - spec/lib/roadie/test_provider_spec.rb
131
132
  - spec/lib/roadie/url_generator_spec.rb
132
133
  - spec/lib/roadie/url_rewriter_spec.rb
134
+ - spec/lib/roadie/utils_spec.rb
133
135
  - spec/shared_examples/asset_provider.rb
134
136
  - spec/shared_examples/url_rewriter.rb
135
137
  - spec/spec_helper.rb
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
160
  version: '0'
159
161
  requirements: []
160
162
  rubyforge_project:
161
- rubygems_version: 2.2.2
163
+ rubygems_version: 2.4.6
162
164
  signing_key:
163
165
  specification_version: 4
164
166
  summary: Making HTML emails comfortable for the Ruby rockstars
@@ -183,6 +185,7 @@ test_files:
183
185
  - spec/lib/roadie/test_provider_spec.rb
184
186
  - spec/lib/roadie/url_generator_spec.rb
185
187
  - spec/lib/roadie/url_rewriter_spec.rb
188
+ - spec/lib/roadie/utils_spec.rb
186
189
  - spec/shared_examples/asset_provider.rb
187
190
  - spec/shared_examples/url_rewriter.rb
188
191
  - spec/spec_helper.rb