Skip to content

A May of WTFs: Raise exception for assets declared without extension #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/sprockets/rails/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ def initialize(view)
end

def asset_path(path, digest, allow_non_precompiled = false)
raise ArgumentError, "asset #{path} should be declared with a filename extension" if File.extname(path).blank?

# Digests enabled? Do the work to calculate the full asset path.
if digest
digest_path path, allow_non_precompiled
Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,14 @@ def test_asset_environment_reference_is_cached
assert_kind_of Sprockets::CachedEnvironment, env
assert @view.assets_environment.equal?(env), "view didn't return the same cached instance"
end

def test_environment_asset_path_without_extension
@view.resolve_assets_with = [ :environment ]

assert_raises(Sprockets::ArgumentError) do
@view.asset_path("logo")
end
end
end

class PrecompiledAssetHelperTest < HelperTest
Expand Down