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

Commit 9d3b054

Browse files
committed
Merge pull request #50 from jwhitley/issue/50
Protect paths config with nil checks
2 parents 32fedd1 + 859563d commit 9d3b054

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

app/helpers/requirejs_helper.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ def requirejs_include_tag(name=nil, &block)
5454
paths = {}
5555
modules.each { |m| paths[m] = _javascript_path(m).sub /\.js$/,'' }
5656

57-
# Add paths for assets specified by full URL (on a CDN)
58-
run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
57+
if run_config.has_key? 'paths'
58+
# Add paths for assets specified by full URL (on a CDN)
59+
run_config['paths'].each { |k,v| paths[k] = v if v =~ /^https?:/ }
60+
end
5961

6062
# Override user paths, whose mappings are only relevant in dev mode
6163
# and in the build_config.

test/requirejs-rails_test.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,15 @@ class RequirejsHelperTest < ActionView::TestCase
126126

127127
def setup
128128
controller.requirejs_included = false
129+
Rails.application.config.requirejs.user_config = {}
130+
Rails.application.config.requirejs.delete(:run_config)
131+
Rails.application.config.requirejs.delete(:build_config)
132+
end
133+
134+
def with_cdn
129135
Rails.application.config.requirejs.user_config = { 'paths' =>
130136
{ 'jquery' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' }
131137
}
132-
133138
end
134139

135140
def wrap(tag)
@@ -163,13 +168,27 @@ def wrap(tag)
163168
end
164169
end
165170

171+
test "requirejs_include_tag with digested asset paths" do
172+
begin
173+
saved_digest = Rails.application.config.assets.digest
174+
Rails.application.config.assets.digest = true
175+
Rails.application.config.requirejs.user_config = { 'modules' => [{'name' => 'foo'}] }
176+
render :text => wrap(requirejs_include_tag)
177+
assert_select "script:first-of-type", :text => %r[var require =.*"paths":{"foo":"/javascripts/foo"}]
178+
ensure
179+
Rails.application.config.assets.digest = saved_digest
180+
end
181+
end
182+
166183
test "requirejs_include_tag with CDN asset in paths" do
184+
with_cdn
167185
render :text => wrap(requirejs_include_tag)
168186
assert_select "script:first-of-type", :text => %r{var require =.*paths.*http://ajax}
169187
end
170188

171189
test "requirejs_include_tag with CDN asset and digested asset paths" do
172190
begin
191+
with_cdn
173192
saved_digest = Rails.application.config.assets.digest
174193
Rails.application.config.assets.digest = true
175194
render :text => wrap(requirejs_include_tag)

0 commit comments

Comments
 (0)