roadie 3.0.3 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +8 -1
- data/README.md +8 -0
- data/lib/roadie/url_generator.rb +16 -5
- data/lib/roadie/version.rb +1 -1
- data/spec/lib/roadie/url_generator_spec.rb +24 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5824c94736e27c2a19d255fe99c7083ad42772b7
|
4
|
+
data.tar.gz: 0c8a41f35860a127e707f6fa115bb15399dbed8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 031ee1cede388f42a4bfbb05ecddcfaf7d42867e28f9e1f08e5645a6fc24efe5dc0a113553ceb6c987eb844ff1fc53e2814eb656ad9ea03709f68662d4f8dc2a
|
7
|
+
data.tar.gz: 290f00e6c0be0773af92d676ec8e7fa4524ecdad17c688ed5fbddc5afd88a7425779cf589f51822270ebc9f6936cf20f417fc2ff79b0aa0b625db63297959488
|
data/Changelog.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
### dev
|
2
2
|
|
3
|
-
[full changelog](https://github.com/Mange/roadie/compare/v3.0.
|
3
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.0.4...master)
|
4
4
|
|
5
5
|
* Nothing yet.
|
6
6
|
|
7
|
+
### 3.0.4
|
8
|
+
|
9
|
+
[full changelog](https://github.com/Mange/roadie/compare/v3.0.3...v3.0.4)
|
10
|
+
|
11
|
+
* Bug fixes:
|
12
|
+
* Schemeless URLs was accepted as-is, which isn't supported in a lot of email clients. (#104)
|
13
|
+
|
7
14
|
### 3.0.3
|
8
15
|
|
9
16
|
[full changelog](https://github.com/Mange/roadie/compare/v3.0.2...v3.0.3)
|
data/README.md
CHANGED
@@ -253,6 +253,14 @@ This project follows [Semantic Versioning](http://semver.org/) and has been sinc
|
|
253
253
|
FAQ
|
254
254
|
---
|
255
255
|
|
256
|
+
### Why is my markup changed in subtle ways?
|
257
|
+
|
258
|
+
Roadie uses Nokogiri to parse and regenerate the HTML of your email, which means that some unintentional changes might show up.
|
259
|
+
|
260
|
+
One example would be that Nokogiri might remove your ` `s in some cases.
|
261
|
+
|
262
|
+
Another example is Nokogiri's lack of HTML5 support, so certain new element might have spaces removed. I recommend you don't use HTML5 in emails anyway because of bad email client support (that includes web mail!).
|
263
|
+
|
256
264
|
### I'm getting segmentation faults (or other C-like problems)! What should I do? ###
|
257
265
|
|
258
266
|
Roadie uses Nokogiri to parse the HTML of your email, so any C-like problems like segfaults are likely in that end. The best way to fix this is to first upgrade libxml2 on your system and then reinstall Nokogiri.
|
data/lib/roadie/url_generator.rb
CHANGED
@@ -26,6 +26,7 @@ module Roadie
|
|
26
26
|
validate_options url_options
|
27
27
|
|
28
28
|
@url_options = url_options
|
29
|
+
@scheme = normalize_scheme(url_options[:scheme] || url_options[:protocol])
|
29
30
|
@root_uri = build_root_uri
|
30
31
|
end
|
31
32
|
|
@@ -55,21 +56,25 @@ module Roadie
|
|
55
56
|
# @return [String] an absolute URL
|
56
57
|
def generate_url(path, base = "/")
|
57
58
|
return root_uri.to_s if path.nil? or path.empty?
|
59
|
+
return add_scheme(path) if path_is_schemeless?(path)
|
58
60
|
return path if path_is_absolute?(path)
|
59
61
|
|
60
62
|
combine_segments(root_uri, base, path).to_s
|
61
63
|
end
|
62
64
|
|
63
65
|
private
|
64
|
-
attr_reader :root_uri
|
66
|
+
attr_reader :root_uri, :scheme
|
65
67
|
|
66
68
|
def build_root_uri
|
67
69
|
path = make_absolute url_options[:path]
|
68
70
|
port = parse_port url_options[:port]
|
69
|
-
scheme = normalize_scheme(url_options[:scheme] || url_options[:protocol])
|
70
71
|
URI::Generic.build(scheme: scheme, host: url_options[:host], port: port, path: path)
|
71
72
|
end
|
72
73
|
|
74
|
+
def add_scheme(path)
|
75
|
+
[scheme, path].join(":")
|
76
|
+
end
|
77
|
+
|
73
78
|
def combine_segments(root, base, path)
|
74
79
|
new_path = apply_base(base, path)
|
75
80
|
if root.path
|
@@ -104,12 +109,18 @@ module Roadie
|
|
104
109
|
end
|
105
110
|
end
|
106
111
|
|
112
|
+
def path_is_schemeless?(path)
|
113
|
+
path =~ %r{^//\w}
|
114
|
+
end
|
115
|
+
|
107
116
|
def path_is_absolute?(path)
|
108
117
|
# Ruby's URI is pretty unforgiving, but roadie aims to be. Don't involve
|
109
118
|
# URI for URLs that's easy to determine to be absolute.
|
110
|
-
# URLs starting with a scheme (http:, data:) are absolute
|
111
|
-
#
|
112
|
-
|
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?
|
113
124
|
end
|
114
125
|
|
115
126
|
def parse_path(path)
|
data/lib/roadie/version.rb
CHANGED
@@ -92,10 +92,6 @@ module Roadie
|
|
92
92
|
expect(url(data_uri, host: "example.com")).to eq(data_uri)
|
93
93
|
end
|
94
94
|
|
95
|
-
it "does not touch absolute URLs without schemes" do
|
96
|
-
expect(url("//assets.myapp.com/foo.jpg", host: "example.com")).to eq("//assets.myapp.com/foo.jpg")
|
97
|
-
end
|
98
|
-
|
99
95
|
it "does not touch custom schemes" do
|
100
96
|
expect(url("myapp://", host: "example.com")).to eq("myapp://")
|
101
97
|
end
|
@@ -106,6 +102,30 @@ module Roadie
|
|
106
102
|
# markers.
|
107
103
|
expect(url("https://foo.com/%|MARKETING_TOKEN|%", host: "example.com")).to eq("https://foo.com/%|MARKETING_TOKEN|%")
|
108
104
|
end
|
105
|
+
|
106
|
+
# A lot of email clients do not support schemeless URLs (it's a HTML5
|
107
|
+
# feature) so we should add a scheme to them.
|
108
|
+
context "on schemeless urls" do
|
109
|
+
# Checking for host matches would be too complex, and it's not too hard
|
110
|
+
# to assume that schemeless URLs to assets comes from a shared
|
111
|
+
# configuration with a web page which uses HTTP and HTTPS in different
|
112
|
+
# cases. That also means that we'd like to match the assets URLs with
|
113
|
+
# whatever we want to link to, most likely.
|
114
|
+
it "adds given scheme, even when host does not match" do
|
115
|
+
result = url("//assets.myapp.com/foo.jpg", host: "example.com", scheme: "https")
|
116
|
+
expect(result).to eq("https://assets.myapp.com/foo.jpg")
|
117
|
+
end
|
118
|
+
|
119
|
+
it "adds standard http: scheme when no scheme given" do
|
120
|
+
result = url("//assets.myapp.com/foo.jpg", host: "example.com")
|
121
|
+
expect(result).to eq("http://assets.myapp.com/foo.jpg")
|
122
|
+
end
|
123
|
+
|
124
|
+
it "adds scheme to invalid URLs" do
|
125
|
+
result = url("//foo.com/%|TOKEN|%", scheme: "ftp", host: "example.com")
|
126
|
+
expect(result).to eq("ftp://foo.com/%|TOKEN|%")
|
127
|
+
end
|
128
|
+
end
|
109
129
|
end
|
110
130
|
|
111
131
|
# URLs in resources that are not based inside the root requires that we may
|
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
|
+
version: 3.0.4
|
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-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|