@@ -30,6 +30,14 @@ def initialize(source)
30
30
end
31
31
end
32
32
33
+ class AbsoluteAssetPathError < ArgumentError
34
+ def initialize ( bad_path , good_path , prefix )
35
+ msg = "Asset names passed to helpers should not include the #{ prefix . inspect } prefix. " <<
36
+ "Instead of #{ bad_path . inspect } , use #{ good_path . inspect } "
37
+ super ( msg )
38
+ end
39
+ end
40
+
33
41
include ActionView ::Helpers ::AssetUrlHelper
34
42
include ActionView ::Helpers ::AssetTagHelper
35
43
@@ -168,15 +176,27 @@ def check_dependencies!(dep)
168
176
depend_on_asset ( dep )
169
177
end
170
178
171
- # Raise errors when source does not exist or is not in the precompiled list
179
+ # Raise errors when source is not in the precompiled list, or
180
+ # incorrectly contains the assets_prefix.
172
181
def check_errors_for ( source , options )
182
+ return unless self . raise_runtime_errors
183
+
173
184
source = source . to_s
174
- return source if !self . raise_runtime_errors || source . blank? || source =~ URI_REGEXP
185
+ return if source . blank? || source =~ URI_REGEXP
186
+
175
187
asset = lookup_asset_for_path ( source , options )
176
188
177
189
if asset && asset_needs_precompile? ( asset . logical_path , asset . pathname . to_s )
178
190
raise AssetFilteredError . new ( asset . logical_path )
179
191
end
192
+
193
+ full_prefix = File . join ( self . assets_prefix || "/" , '' )
194
+ if !asset && source . start_with? ( full_prefix )
195
+ short_path = source [ full_prefix . size , source . size ]
196
+ if lookup_asset_for_path ( short_path , options )
197
+ raise AbsoluteAssetPathError . new ( source , short_path , full_prefix )
198
+ end
199
+ end
180
200
end
181
201
182
202
# Returns true when an asset will not be available after precompile is run
0 commit comments