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
update for frozen string literals #1101
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env ruby -I ../lib -I lib | ||
# frozen_string_literal: true | ||
require 'sinatra' | ||
get('/') { 'this is a simple app' } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'sinatra/main' | ||
|
||
enable :inline_templates |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here as well, I'm not sure this change is necessary as we haven't seen any failures in this case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zzak I just ran across this in one of our projects. See #1137. We tried to freeze the constant we were using to set dispositions and got lots of errors.. Also this fixed a possible unintended side effect bug. If you hold a reference to the string you pass as the disposition, you'll find that string changed after the call.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @aselder Thanks for your investigation! I will consider your patch, and this one but unfortunately I don't want to merge all of these comments in the test files. |
||
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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you provide a case where body is actually immutable from here? Maybe an empty request? |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'sinatra/base' | ||
|
||
module Sinatra | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
module Sinatra | ||
VERSION = '2.0.0-alpha' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class BaseTest < Minitest::Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# encoding: UTF-8 | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
require 'erb' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class ERBTest < Minitest::Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
ENV['RACK_ENV'] = 'test' | ||
Encoding.default_external = "UTF-8" if defined? Encoding | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
require 'date' | ||
require 'json' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
$stderr.puts "loading" | ||
require 'sinatra' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require 'sinatra/base' | ||
require 'rbconfig' | ||
require 'open-uri' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class FooError < RuntimeError | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
MarkdownTest = proc do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
require 'rack' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
require 'stringio' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# encoding: utf-8 | ||
# frozen_string_literal: true | ||
|
||
require File.expand_path('../helper', __FILE__) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class ResultTest < Minitest::Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
module RouteAddedTest | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
require 'stringio' | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
class StaticTest < Minitest::Test | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<%# frozen_string_literal: true %> | ||
This file has no unicode in it! | ||
<%= value %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<%= 1 + 1 %> | ||
<%# frozen_string_literal: true %> | ||
<%= 1 + 1 %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<%# frozen_string_literal: true %> | ||
Hello <%= 'World' %> | ||
<% raise 'Goodbye' unless defined?(french) && french %> | ||
<% raise 'Au revoir' if defined?(french) && french %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
<%# frozen_string_literal: true %> | ||
Hello <%= 'World' %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
-# frozen_string_literal: true | ||
%h1 Hello From Haml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<%# frozen_string_literal: true %> | ||
ERB Layout! | ||
<%= yield %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
-# frozen_string_literal: true | ||
%h1 HAML Layout! | ||
%p= yield |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
<%# frozen_string_literal: true %> | ||
<h1><%= value %></h1> | ||
Ingen vill veta var du köpt din tröja. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# frozen_string_literal: true | ||
require File.expand_path('../helper', __FILE__) | ||
|
||
begin | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed for the one string allocated here "sinatra/main" is an acceptable allocation that I doubt will be repeated enough to affect performance