Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjtko/3946516 to your computer and use it in GitHub Desktop.
Save mjtko/3946516 to your computer and use it in GitHub Desktop.
Monkey patch for denying TTF files to PhantomJS under test env
# config/initializers/sprockets-server-monkeypatch-deny_phantomjs_ttf.rb
# Monkey patch under test environment that prevents PhantomJS on OSX
# from crashing when dealing with TTF webfonts.
# Note: depending on your setup, it's likely that the RUBY_PLATFORM
# is not actually relevant for server - it's the UA that crashes.
if Rails.env.test? # && RUBY_PLATFORM =~ /darwin/
module Sprockets::Server
def call_with_env_instance_var(env)
@env = env
call_without_env_instance_var(env)
end
alias_method_chain :call, :env_instance_var
def forbidden_request?(path)
if @env['HTTP_USER_AGENT'] =~ /Intel Mac OS X.*PhantomJS/ && path =~ /ttf$/
STDERR.puts "Denying #{path} to #{@env['HTTP_USER_AGENT']}"
true
else
path.include?("..")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment