Skip to content
This repository was archived by the owner on Mar 23, 2024. It is now read-only.

Commit 1201570

Browse files
committed
Merge pull request #192 from remybach/remybach-allow_protocol_relative_urls
Allow protocol relative urls for CDNs within paths
2 parents f1016f0 + 1d083a1 commit 1201570

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def requirejs_include_tag(name = nil, &block)
4949
if run_config.has_key? 'paths'
5050
# Add paths for assets specified by full URL (on a CDN)
5151
run_config['paths'].each do |k, v|
52-
paths[k] = v if v.is_a?(Array) || v =~ /^https?:/
52+
paths[k] = v if v.is_a?(Array) || v =~ /^(https?:)?\/\//
53+
5354
end
5455
end
5556

test/requirejs-rails_test.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def setup
110110
Rails.application.config.requirejs.delete(:build_config)
111111
end
112112

113-
def with_cdn
113+
def with_cdn(protocol_relative = false)
114114
Rails.application.config.requirejs.user_config = {
115115
"paths" => {
116-
"jquery" => "http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
116+
"jquery" => "#{ protocol_relative ? '' : 'http:' }//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"
117117
}
118118
}
119119
end
@@ -199,4 +199,13 @@ def wrap(tag)
199199
Rails.application.config.assets.digest = saved_digest
200200
end
201201
end
202+
203+
test "requirejs_include_tag with protocol relative CDN asset in paths" do
204+
with_cdn(true)
205+
206+
render text: wrap(requirejs_include_tag)
207+
208+
assert_select "script:last-of-type",
209+
text: Regexp.new("\\Arequire\\.config\\({.*\"paths\":{.*\"//ajax\\..*\".*}.*}\\);\\z")
210+
end
202211
end

0 commit comments

Comments
 (0)