diff --git a/Changelog.md b/Changelog.md index 2679ae40fc1ea08496a8ca411c0c4db2d83313d4..d18c5f595fd3e9d5755a567b9d235bc079f09d2e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -147,6 +147,7 @@ Contributions are very welcome, the hard work is done! ## Features * Added the footer to conversation pages [#6710](https://github.com/diaspora/diaspora/pull/6710) +* Drop ChromeFrame and display an error page on old IE versions instead [#6751](https://github.com/diaspora/diaspora/pull/6751) # 0.5.7.1 diff --git a/config.ru b/config.ru index 9603dbba347ff055a06c508d5ed18609f7b2d42e..e2524860075a6d80a3bed0413e13a1e767f631a3 100644 --- a/config.ru +++ b/config.ru @@ -1,19 +1,19 @@ - # Copyright (c) 2010-2011, Diaspora Inc. This file is +# Copyright (c) 2010-2011, Diaspora Inc. This file is # licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. # This file is used by Rack-based servers to start the application. -require ::File.expand_path('../config/environment', __FILE__) -require ::File.expand_path('../lib/unicorn_killer', __FILE__) -require ::File.expand_path('../lib/rack/chrome_frame', __FILE__) +require ::File.expand_path("../config/environment", __FILE__) +require ::File.expand_path("../lib/unicorn_killer", __FILE__) +require ::File.expand_path("../lib/rack/internet_explorer_version", __FILE__) -# Kill unicorn workers really agressively (at 300mb) +# Kill unicorn workers really aggressively (at 300mb) if defined?(Unicorn) use UnicornKiller::Oom, 300 * 1024 end use Rack::Deflater -use Rack::ChromeFrame, :minimum => 8 +use Rack::InternetExplorerVersion, minimum: 9 use Rack::Protection::FrameOptions run Diaspora::Application diff --git a/lib/rack/chrome_frame.rb b/lib/rack/chrome_frame.rb deleted file mode 100644 index 3e4955cf8a02cb5d1e817099f4484942fb39cf5d..0000000000000000000000000000000000000000 --- a/lib/rack/chrome_frame.rb +++ /dev/null @@ -1,71 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -module Rack - class ChromeFrame - - def initialize(app, options={}) - @app = app - @options = options - end - - def call(env) - - if env['HTTP_USER_AGENT'] =~ /MSIE/ - if env['HTTP_USER_AGENT'] =~ /chromeframe/ - status, headers, response = @app.call(env) - new_body = insert_tag(build_response_body(response)) - new_headers = recalculate_body_length(headers, new_body) - return [status, new_headers, [new_body]] - elsif @options[:minimum].nil? or ie_version(env['HTTP_USER_AGENT']) < @options[:minimum] - html = <<-HTML - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> - <head> - <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> - <title>Diaspora doesn't support your version of Internet Explorer. Try Chrome, Firefox, or Opera!</title> - </head> - <body> - <div id="cf-placeholder"></div> - <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js"></script> - <script>CFInstall.check({ node: "cf-placeholder" #{', destination: "' + @options[:destination] + '" ' if @options[:destination]}});</script> - </body> - </html> - HTML - return [200, {'Content-Type' => 'text/html', 'Content-Length' => html.size.to_s}, Rack::Response.new([html])] - end - end - @app.call(env) - end - - def build_response_body(response) - response_body = "" - response.each { |part| response_body += part } - - # see: http://johnbintz.github.com/blog/2012/03/05/closing-given-body-in-rack-middleware/ - response.close if response.respond_to?(:close) - - response_body - end - - def recalculate_body_length(headers, body) - new_headers = headers - new_headers["Content-Length"] = body.length.to_s - new_headers - end - - def insert_tag(body) - head = <<-HEAD - <meta http-equiv="X-UA-Compatible" content="chrome=1"> - HEAD - - body.gsub!(/<head(.*)>/, "<head\\1>\n" + head ) - body - end - - def ie_version(ua_string) - ua_string.match(/MSIE ?(\S+)/)[1].to_f - end - end -end diff --git a/lib/rack/internet_explorer_version.rb b/lib/rack/internet_explorer_version.rb new file mode 100644 index 0000000000000000000000000000000000000000..4d3b4446838887aa01eeb92e4327f04de4a79839 --- /dev/null +++ b/lib/rack/internet_explorer_version.rb @@ -0,0 +1,41 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module Rack + class InternetExplorerVersion + def initialize(app, options={}) + @app = app + @options = options + end + + def call(env) + if env["HTTP_USER_AGENT"] =~ /MSIE/ && ie_version(env["HTTP_USER_AGENT"]) < @options[:minimum] + html = <<-HTML + <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> + <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> + <title>Diaspora doesn't support your version of Internet Explorer. Try Firefox, Chrome or Opera!</title> + </head> + <body> + <h1>Diaspora doesn't support your version of Internet Explorer.</h1> + You can use one of these browsers (and many more): + <ul> + <li><a href="https://www.mozilla.org/firefox/">Firefox</a></li> + <li><a href="https://www.google.com/chrome/">Chrome</a></li> + <li><a href="https://www.opera.com/">Opera</a></li> + </ul> + </body> + </html> + HTML + return [200, {"Content-Type" => "text/html", "Content-Length" => html.size.to_s}, Rack::Response.new([html])] + end + @app.call(env) + end + + def ie_version(ua_string) + ua_string.match(/MSIE ?(\S+)/)[1].to_f + end + end +end diff --git a/spec/lib/rack/chrome_frame_spec.rb b/spec/lib/rack/chrome_frame_spec.rb deleted file mode 100644 index e7feaf15da19e8f4216cb730c1eab60227222fad..0000000000000000000000000000000000000000 --- a/spec/lib/rack/chrome_frame_spec.rb +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -require 'spec_helper' - -describe Rack::ChromeFrame do - - before :all do - @app = Rack::Builder.parse_file(Rails.root.join('config.ru').to_s).first - end - - before :each do - @response = get_response_for_user_agent(@app, ua_string); - end - - subject { @response } - - context "non-IE browser" do - let(:ua_string) { "another browser chromeframe" } - - it "shouldn't complain about the browser and shouldn't have chrome frame" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end - - context "IE8 without chromeframe" do - let(:ua_string) { "MSIE 8" } - - it "shouldn't complain about the browser and shouldn't have chrome frame" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end - - context "IE7 without chromeframe" do - let(:ua_string) { "MSIE 7" } - - it "should complain about the browser" do - expect(subject.body).not_to match(/chrome=1/) - expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) - end - specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} - end - - context "any IE with chromeframe" do - let(:ua_string) { "MSIE number chromeframe" } - - it "shouldn't complain about the browser and should have chrome frame" do - expect(subject.body).to match(/chrome=1/) - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - specify {expect(@response.headers["Content-Length"]).to eq(@response.body.length.to_s)} - end - - context "Specific case with no space after MSIE" do - let(:ua_string) { "Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727" } - - it "shouldn't complain about the browser" do - expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) - end - end -end diff --git a/spec/lib/rack/internet_explorer_version_spec.rb b/spec/lib/rack/internet_explorer_version_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..2bc7a75c0c7a7606310cf7525da9344ee5fdbe42 --- /dev/null +++ b/spec/lib/rack/internet_explorer_version_spec.rb @@ -0,0 +1,48 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. +require "spec_helper" + +describe Rack::InternetExplorerVersion do + before :all do + @app = Rack::Builder.parse_file(Rails.root.join("config.ru").to_s).first + end + + subject { get_response_for_user_agent(@app, ua_string) } + + context "non-IE browser" do + let(:ua_string) { "another browser chromeframe" } + + it "shouldn't complain about the browser" do + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end + + context "new IE" do + let(:ua_string) { "MSIE 9" } + + it "shouldn't complain about the browser" do + expect(subject.body).not_to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end + + context "old IE" do + let(:ua_string) { "MSIE 7" } + + it "should complain about the browser" do + expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) + end + + it "should have the correct content-length header" do + expect(subject.headers["Content-Length"]).to eq(subject.body.length.to_s) + end + end + + context "Specific case with no space after MSIE" do + let(:ua_string) { "Mozilla/4.0 (compatible; MSIE8.0; Windows NT 6.0) .NET CLR 2.0.50727" } + + it "should complain about the browser" do + expect(subject.body).to match(/Diaspora doesn't support your version of Internet Explorer/) + end + end +end