Sha256: 0def226c1ed2a1207e96c650e8c65cc8d6a610526429453519816ee506825af6

Contents?: true

Size: 789 Bytes

Versions: 1

Compression:

Stored size: 789 Bytes

Contents

class JavascriptEraser
  def initialize(app)
    @app = app
  end

  def call(env)
    status, headers, response = @app.call(env)

    if headers['Content-Type'] and headers['Content-Type'].include?("javascript")
      response = ""
    elsif response.respond_to?(:body) and response.body.is_a?(String)
      response.body = response.body.gsub(/<script(.|\n)*?type(.|\n)*?javascript(.|\n)*?\/script>/,"")
      response.body = response.body.gsub(/\s*on\w+=".*?[^\\]"\s*(.*?)\s*>/, "\\1>")
      response.body = response.body.gsub(/\s*on\w+='.*?[^\\]'\s*(.*?)\s*>/, "\\1>")
    elsif response.class.to_s != "Rack::File"
      puts "JavascriptEraser: unknown response type: #{response.class}. check order of appearance in middleware stack."
    end

    [status, headers, response]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
javascript_eraser-1.0.2 lib/javascript_eraser.rb