@@ -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
if defined? ActionView ::Helpers ::AssetUrlHelper
34
42
include ActionView ::Helpers ::AssetUrlHelper
35
43
include ActionView ::Helpers ::AssetTagHelper
@@ -176,15 +184,27 @@ def check_dependencies!(dep)
176
184
rescue Sprockets ::FileNotFound
177
185
end
178
186
179
- # Raise errors when source does not exist or is not in the precompiled list
187
+ # Raise errors when source is not in the precompiled list, or
188
+ # incorrectly contains the assets_prefix.
180
189
def check_errors_for ( source , options )
190
+ return unless self . raise_runtime_errors
191
+
181
192
source = source . to_s
182
- return source if !self . raise_runtime_errors || source . blank? || source =~ URI_REGEXP
193
+ return if source . blank? || source =~ URI_REGEXP
194
+
183
195
asset = lookup_asset_for_path ( source , options )
184
196
185
197
if asset && asset_needs_precompile? ( asset . logical_path , asset . pathname . to_s )
186
198
raise AssetFilteredError . new ( asset . logical_path )
187
199
end
200
+
201
+ full_prefix = File . join ( self . assets_prefix || "/" , '' )
202
+ if !asset && source . start_with? ( full_prefix )
203
+ short_path = source [ full_prefix . size , source . size ]
204
+ if lookup_asset_for_path ( short_path , options )
205
+ raise AbsoluteAssetPathError . new ( source , short_path , full_prefix )
206
+ end
207
+ end
188
208
end
189
209
190
210
# Returns true when an asset will not be available after precompile is run
0 commit comments