From 879d408b6f0205717f44c477a8a42dd4b488f352 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Sat, 5 Mar 2016 20:45:07 -0800 Subject: [PATCH] update for frozen string literals --- examples/chat.rb | 1 + examples/simple.rb | 1 + lib/sinatra.rb | 1 + lib/sinatra/base.rb | 10 ++++++++-- lib/sinatra/main.rb | 1 + lib/sinatra/version.rb | 1 + test/asciidoctor_test.rb | 1 + test/base_test.rb | 1 + test/builder_test.rb | 1 + test/coffee_test.rb | 1 + test/compile_test.rb | 1 + test/contest.rb | 1 + test/creole_test.rb | 1 + test/delegator_test.rb | 1 + test/encoding_test.rb | 1 + test/erb_test.rb | 1 + test/extensions_test.rb | 1 + test/filter_test.rb | 1 + test/haml_test.rb | 1 + test/helper.rb | 1 + test/helpers_test.rb | 1 + test/integration/app.rb | 1 + test/integration_helper.rb | 1 + test/integration_test.rb | 1 + test/less_test.rb | 1 + test/liquid_test.rb | 1 + test/mapped_error_test.rb | 1 + test/markaby_test.rb | 1 + test/markdown_test.rb | 1 + test/mediawiki_test.rb | 1 + test/middleware_test.rb | 1 + test/nokogiri_test.rb | 1 + test/rabl_test.rb | 1 + test/rack_test.rb | 1 + test/radius_test.rb | 1 + test/rdoc_test.rb | 1 + test/readme_test.rb | 1 + test/request_test.rb | 1 + test/response_test.rb | 1 + test/result_test.rb | 1 + test/route_added_hook_test.rb | 1 + test/routing_test.rb | 1 + test/sass_test.rb | 1 + test/scss_test.rb | 1 + test/server_test.rb | 1 + test/settings_test.rb | 1 + test/sinatra_test.rb | 1 + test/slim_test.rb | 1 + test/static_test.rb | 1 + test/streaming_test.rb | 1 + test/stylus_test.rb | 1 + test/templates_test.rb | 1 + test/textile_test.rb | 1 + test/views/ascii.erb | 1 + test/views/calc.html.erb | 3 ++- test/views/error.erb | 1 + test/views/error.haml | 1 + test/views/hello.erb | 1 + test/views/hello.haml | 1 + test/views/layout2.erb | 1 + test/views/layout2.haml | 1 + test/views/utf8.erb | 1 + test/wlang_test.rb | 1 + test/yajl_test.rb | 1 + 64 files changed, 72 insertions(+), 3 deletions(-) diff --git a/examples/chat.rb b/examples/chat.rb index 8e47b7d1b3..d1639503fc 100755 --- a/examples/chat.rb +++ b/examples/chat.rb @@ -1,5 +1,6 @@ #!/usr/bin/env ruby -I ../lib -I lib # coding: utf-8 +# frozen_string_literal: true require 'sinatra' set :server, 'thin' connections = [] diff --git a/examples/simple.rb b/examples/simple.rb index 2697f94bf2..d1cce864f7 100755 --- a/examples/simple.rb +++ b/examples/simple.rb @@ -1,3 +1,4 @@ #!/usr/bin/env ruby -I ../lib -I lib +# frozen_string_literal: true require 'sinatra' get('/') { 'this is a simple app' } diff --git a/lib/sinatra.rb b/lib/sinatra.rb index 68261380cb..504dd8c7c2 100644 --- a/lib/sinatra.rb +++ b/lib/sinatra.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'sinatra/main' enable :inline_templates diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index a08d2db75f..1411be50a9 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -348,7 +348,7 @@ def attachment(filename = nil, disposition = :attachment) response['Content-Disposition'] = disposition.to_s if filename params = '; filename="%s"' % File.basename(filename) - response['Content-Disposition'] << params + response['Content-Disposition'] += params ext = File.extname(filename) content_type(ext) unless response['Content-Type'] or ext.empty? end @@ -842,6 +842,7 @@ def compile_template(engine, data, options, views) body, path, line = settings.templates[data] if body body = body.call if body.respond_to?(:call) + body = body.dup if body.frozen? template.new(path, line.to_i, options) { body } else found = false @@ -857,7 +858,12 @@ def compile_template(engine, data, options, views) template.new(path, 1, options) end when Proc, String - body = data.is_a?(String) ? Proc.new { data } : data + body = if data.is_a?(String) + data = data.dup if data.frozen? + Proc.new { data } + else + data + end path, line = settings.caller_locations.first template.new(path, line.to_i, options, &body) else diff --git a/lib/sinatra/main.rb b/lib/sinatra/main.rb index 76a55261af..c734759c7d 100644 --- a/lib/sinatra/main.rb +++ b/lib/sinatra/main.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'sinatra/base' module Sinatra diff --git a/lib/sinatra/version.rb b/lib/sinatra/version.rb index 0e48ab1194..bef9101d88 100644 --- a/lib/sinatra/version.rb +++ b/lib/sinatra/version.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true module Sinatra VERSION = '2.0.0-alpha' end diff --git a/test/asciidoctor_test.rb b/test/asciidoctor_test.rb index 6d64b047dc..6dbdc2c135 100644 --- a/test/asciidoctor_test.rb +++ b/test/asciidoctor_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/base_test.rb b/test/base_test.rb index a6730373ec..f8ec6a1617 100644 --- a/test/base_test.rb +++ b/test/base_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class BaseTest < Minitest::Test diff --git a/test/builder_test.rb b/test/builder_test.rb index 29c6d29c08..ee1d4e25ba 100644 --- a/test/builder_test.rb +++ b/test/builder_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/coffee_test.rb b/test/coffee_test.rb index 8a5bee1d52..3a4a0fd2f9 100644 --- a/test/coffee_test.rb +++ b/test/coffee_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/compile_test.rb b/test/compile_test.rb index baa3a4c3df..104aded7b9 100644 --- a/test/compile_test.rb +++ b/test/compile_test.rb @@ -1,4 +1,5 @@ # I like coding: UTF-8 +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class CompileTest < Minitest::Test diff --git a/test/contest.rb b/test/contest.rb index 2b68c4148b..f116f77305 100644 --- a/test/contest.rb +++ b/test/contest.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Copyright (c) 2009 Damian Janowski and Michel Martens for Citrusbyte # # Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/test/creole_test.rb b/test/creole_test.rb index 76b305f89c..432ca887e7 100644 --- a/test/creole_test.rb +++ b/test/creole_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/delegator_test.rb b/test/delegator_test.rb index bd4425eb63..e940a5e72d 100644 --- a/test/delegator_test.rb +++ b/test/delegator_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class DelegatorTest < Minitest::Test diff --git a/test/encoding_test.rb b/test/encoding_test.rb index 61a9f9338e..ab92f26406 100644 --- a/test/encoding_test.rb +++ b/test/encoding_test.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require 'erb' diff --git a/test/erb_test.rb b/test/erb_test.rb index 325da9c4ab..6bd1739d99 100644 --- a/test/erb_test.rb +++ b/test/erb_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class ERBTest < Minitest::Test diff --git a/test/extensions_test.rb b/test/extensions_test.rb index b0d7e84574..d011cd7cd0 100644 --- a/test/extensions_test.rb +++ b/test/extensions_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class ExtensionsTest < Minitest::Test diff --git a/test/filter_test.rb b/test/filter_test.rb index f708015bd6..613a3dfa28 100644 --- a/test/filter_test.rb +++ b/test/filter_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class BeforeFilterTest < Minitest::Test diff --git a/test/haml_test.rb b/test/haml_test.rb index c3a32cc19b..cb04392acf 100644 --- a/test/haml_test.rb +++ b/test/haml_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/helper.rb b/test/helper.rb index 49ce119aea..e45255208a 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true ENV['RACK_ENV'] = 'test' Encoding.default_external = "UTF-8" if defined? Encoding diff --git a/test/helpers_test.rb b/test/helpers_test.rb index f56fe24ce3..4ba9c86055 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require 'date' require 'json' diff --git a/test/integration/app.rb b/test/integration/app.rb index 3e87a00aaf..e1f2e0d306 100644 --- a/test/integration/app.rb +++ b/test/integration/app.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true $stderr.puts "loading" require 'sinatra' diff --git a/test/integration_helper.rb b/test/integration_helper.rb index 5e6c55a10a..0eaa63b1f9 100644 --- a/test/integration_helper.rb +++ b/test/integration_helper.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require 'sinatra/base' require 'rbconfig' require 'open-uri' diff --git a/test/integration_test.rb b/test/integration_test.rb index feda6e02aa..2d5c0e4e2d 100644 --- a/test/integration_test.rb +++ b/test/integration_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require File.expand_path('../integration_helper', __FILE__) diff --git a/test/less_test.rb b/test/less_test.rb index 10276fd158..76fdd0ac98 100644 --- a/test/less_test.rb +++ b/test/less_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/liquid_test.rb b/test/liquid_test.rb index 57fcb6c948..9d202fcec6 100644 --- a/test/liquid_test.rb +++ b/test/liquid_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/mapped_error_test.rb b/test/mapped_error_test.rb index cb158a2683..47ffedd653 100644 --- a/test/mapped_error_test.rb +++ b/test/mapped_error_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class FooError < RuntimeError diff --git a/test/markaby_test.rb b/test/markaby_test.rb index fcc7d3330c..7706ebf503 100644 --- a/test/markaby_test.rb +++ b/test/markaby_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/markdown_test.rb b/test/markdown_test.rb index 7c7deecf37..5ca39518df 100644 --- a/test/markdown_test.rb +++ b/test/markdown_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) MarkdownTest = proc do diff --git a/test/mediawiki_test.rb b/test/mediawiki_test.rb index 759aa23551..3bba20a89c 100644 --- a/test/mediawiki_test.rb +++ b/test/mediawiki_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/middleware_test.rb b/test/middleware_test.rb index 8a6e836c4e..4cd1939c5c 100644 --- a/test/middleware_test.rb +++ b/test/middleware_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class MiddlewareTest < Minitest::Test diff --git a/test/nokogiri_test.rb b/test/nokogiri_test.rb index e2a1c135c8..587df196f3 100644 --- a/test/nokogiri_test.rb +++ b/test/nokogiri_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/rabl_test.rb b/test/rabl_test.rb index c9303a12c3..d6c9859eaf 100644 --- a/test/rabl_test.rb +++ b/test/rabl_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/rack_test.rb b/test/rack_test.rb index 8ac81d420b..127057b60a 100644 --- a/test/rack_test.rb +++ b/test/rack_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require 'rack' diff --git a/test/radius_test.rb b/test/radius_test.rb index 214cd4ebd5..29b355ba20 100644 --- a/test/radius_test.rb +++ b/test/radius_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/rdoc_test.rb b/test/rdoc_test.rb index cb928dd0cc..a519fb2567 100644 --- a/test/rdoc_test.rb +++ b/test/rdoc_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/readme_test.rb b/test/readme_test.rb index 4da41038be..44e3d36b50 100644 --- a/test/readme_test.rb +++ b/test/readme_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true # Tests to check if all the README examples work. require File.expand_path('../helper', __FILE__) diff --git a/test/request_test.rb b/test/request_test.rb index 4434589c32..97e7833d60 100644 --- a/test/request_test.rb +++ b/test/request_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require 'stringio' diff --git a/test/response_test.rb b/test/response_test.rb index ae4608d798..5d3aae0e69 100644 --- a/test/response_test.rb +++ b/test/response_test.rb @@ -1,4 +1,5 @@ # encoding: utf-8 +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) diff --git a/test/result_test.rb b/test/result_test.rb index dd1eb818f9..b079024bf6 100644 --- a/test/result_test.rb +++ b/test/result_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class ResultTest < Minitest::Test diff --git a/test/route_added_hook_test.rb b/test/route_added_hook_test.rb index 2356166f3b..9979c7740f 100644 --- a/test/route_added_hook_test.rb +++ b/test/route_added_hook_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) module RouteAddedTest diff --git a/test/routing_test.rb b/test/routing_test.rb index 5756731268..924ef9f5dc 100644 --- a/test/routing_test.rb +++ b/test/routing_test.rb @@ -1,4 +1,5 @@ # I like coding: UTF-8 +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) # Helper method for easy route pattern matching testing diff --git a/test/sass_test.rb b/test/sass_test.rb index a8cbf6fe1e..ffc5bf6501 100644 --- a/test/sass_test.rb +++ b/test/sass_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/scss_test.rb b/test/scss_test.rb index 1db2effd76..6dcaa080ab 100644 --- a/test/scss_test.rb +++ b/test/scss_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/server_test.rb b/test/server_test.rb index cdd243baea..57c0f9296e 100644 --- a/test/server_test.rb +++ b/test/server_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) require 'stringio' diff --git a/test/settings_test.rb b/test/settings_test.rb index 1b135f56d3..2268a142c8 100644 --- a/test/settings_test.rb +++ b/test/settings_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class SettingsTest < Minitest::Test diff --git a/test/sinatra_test.rb b/test/sinatra_test.rb index b27120a06c..53090eb086 100644 --- a/test/sinatra_test.rb +++ b/test/sinatra_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class SinatraTest < Minitest::Test diff --git a/test/slim_test.rb b/test/slim_test.rb index a3ad739751..6d09e3427d 100644 --- a/test/slim_test.rb +++ b/test/slim_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/static_test.rb b/test/static_test.rb index a00c5cf250..04772ddb21 100644 --- a/test/static_test.rb +++ b/test/static_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class StaticTest < Minitest::Test diff --git a/test/streaming_test.rb b/test/streaming_test.rb index cc1abe7032..f4a4052cab 100644 --- a/test/streaming_test.rb +++ b/test/streaming_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) class StreamingTest < Minitest::Test diff --git a/test/stylus_test.rb b/test/stylus_test.rb index 9c7e7fd0c3..14e7536ae5 100644 --- a/test/stylus_test.rb +++ b/test/stylus_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/templates_test.rb b/test/templates_test.rb index 3548f8f5b0..1d7aafbc40 100644 --- a/test/templates_test.rb +++ b/test/templates_test.rb @@ -1,4 +1,5 @@ # encoding: UTF-8 +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) File.delete(File.dirname(__FILE__) + '/views/layout.test') rescue nil diff --git a/test/textile_test.rb b/test/textile_test.rb index 33e01e0009..8a1078b864 100644 --- a/test/textile_test.rb +++ b/test/textile_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/views/ascii.erb b/test/views/ascii.erb index 094e6a8e21..840d92bc05 100644 --- a/test/views/ascii.erb +++ b/test/views/ascii.erb @@ -1,2 +1,3 @@ +<%# frozen_string_literal: true %> This file has no unicode in it! <%= value %> diff --git a/test/views/calc.html.erb b/test/views/calc.html.erb index ff47b84757..41bb7287fc 100644 --- a/test/views/calc.html.erb +++ b/test/views/calc.html.erb @@ -1 +1,2 @@ -<%= 1 + 1 %> \ No newline at end of file +<%# frozen_string_literal: true %> +<%= 1 + 1 %> diff --git a/test/views/error.erb b/test/views/error.erb index b48d1f060e..34dc781609 100644 --- a/test/views/error.erb +++ b/test/views/error.erb @@ -1,3 +1,4 @@ +<%# frozen_string_literal: true %> Hello <%= 'World' %> <% raise 'Goodbye' unless defined?(french) && french %> <% raise 'Au revoir' if defined?(french) && french %> diff --git a/test/views/error.haml b/test/views/error.haml index 6019007b26..a2df53afa7 100644 --- a/test/views/error.haml +++ b/test/views/error.haml @@ -1,3 +1,4 @@ +-# frozen_string_literal: true %h1 Hello From Haml = raise 'goodbye' unless defined?(french) && french = raise 'au revoir' if defined?(french) && french diff --git a/test/views/hello.erb b/test/views/hello.erb index bcbbc926f4..8c47cd271e 100644 --- a/test/views/hello.erb +++ b/test/views/hello.erb @@ -1 +1,2 @@ +<%# frozen_string_literal: true %> Hello <%= 'World' %> diff --git a/test/views/hello.haml b/test/views/hello.haml index d6852a6098..a56c94c77d 100644 --- a/test/views/hello.haml +++ b/test/views/hello.haml @@ -1 +1,2 @@ +-# frozen_string_literal: true %h1 Hello From Haml diff --git a/test/views/layout2.erb b/test/views/layout2.erb index e097f3b6e0..2eb784b5fc 100644 --- a/test/views/layout2.erb +++ b/test/views/layout2.erb @@ -1,2 +1,3 @@ +<%# frozen_string_literal: true %> ERB Layout! <%= yield %> diff --git a/test/views/layout2.haml b/test/views/layout2.haml index 58bfc04de4..175c63deb8 100644 --- a/test/views/layout2.haml +++ b/test/views/layout2.haml @@ -1,2 +1,3 @@ +-# frozen_string_literal: true %h1 HAML Layout! %p= yield diff --git a/test/views/utf8.erb b/test/views/utf8.erb index de743c5bee..50bceea830 100644 --- a/test/views/utf8.erb +++ b/test/views/utf8.erb @@ -1,2 +1,3 @@ +<%# frozen_string_literal: true %>

<%= value %>

Ingen vill veta var du köpt din tröja. diff --git a/test/wlang_test.rb b/test/wlang_test.rb index 142ca571a7..be4a5239bd 100644 --- a/test/wlang_test.rb +++ b/test/wlang_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin diff --git a/test/yajl_test.rb b/test/yajl_test.rb index 2f00f069df..6e40020ec5 100644 --- a/test/yajl_test.rb +++ b/test/yajl_test.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true require File.expand_path('../helper', __FILE__) begin