From 46a597a594125df82ec3ff836d1d2f8e6b0d37c0 Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Mon, 31 Oct 2016 16:50:44 -0700 Subject: [PATCH 1/9] update dependencies to run on ruby 2.x --- .ruby-version | 1 + Gemfile | 3 ++- Gemfile.lock | 21 ++++++++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000000000..63a1a1ca3c483 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.1.9 diff --git a/Gemfile b/Gemfile index f14076017c08a..1834fd54d19c6 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem 'mysql', '=2.8.1' gem 'rack', '< 1.5' gem 'pg', '=0.9.0' gem 'nokogiri', '1.3.3' -gem 'libxml-ruby', '=1.1.4' +gem 'libxml-ruby', '2.9.0' +gem 'iconv', '1.0.4' gem 'railslts-version', :path => 'railslts-version' diff --git a/Gemfile.lock b/Gemfile.lock index a69a1823ae9ef..d9c1f641518f5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,15 +7,26 @@ GEM remote: https://rubygems.org/ specs: RedCloth (4.2.3) - libxml-ruby (1.1.4) + hoe (3.15.2) + rake (>= 0.8, < 12.0) + iconv (1.0.4) + libxml-ruby (2.9.0) mocha (0.9.7) rake mysql (2.8.1) nokogiri (1.3.3) + hoe (>= 2.3.2) + racc + rake-compiler + rexical pg (0.9.0) - rack (1.4.6) + racc (1.4.14) + rack (1.4.7) rake (0.8.7) + rake-compiler (1.0.1) + rake rdoc (2.5.11) + rexical (1.0.5) sqlite3 (1.3.7) PLATFORMS @@ -23,7 +34,8 @@ PLATFORMS DEPENDENCIES RedCloth (= 4.2.3) - libxml-ruby (= 1.1.4) + iconv (= 1.0.4) + libxml-ruby (= 2.9.0) mocha (= 0.9.7) mysql (= 2.8.1) nokogiri (= 1.3.3) @@ -33,3 +45,6 @@ DEPENDENCIES rake (= 0.8.7) rdoc (= 2.5.11) sqlite3 (= 1.3.7) + +BUNDLED WITH + 1.13.6 From 07215e54233aa1ffa080c1cc078d2ccd74b99ef0 Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Mon, 31 Oct 2016 16:52:18 -0700 Subject: [PATCH 2/9] change the primary key type for mysql adapter to work with mysql = 5.7 --- .../lib/active_record/connection_adapters/mysql_adapter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb index c50022bd89c91..31cb6ce7efdef 100644 --- a/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb @@ -182,7 +182,7 @@ class MysqlAdapter < AbstractAdapter QUOTED_TRUE, QUOTED_FALSE = '1'.freeze, '0'.freeze NATIVE_DATABASE_TYPES = { - :primary_key => "int(11) DEFAULT NULL auto_increment PRIMARY KEY".freeze, + :primary_key => "int(11) auto_increment PRIMARY KEY".freeze, :string => { :name => "varchar", :limit => 255 }, :text => { :name => "text" }, :integer => { :name => "int", :limit => 4 }, From 3c21a80163adca8a6231078925d3995b85fd0a0a Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Mon, 31 Oct 2016 16:58:27 -0700 Subject: [PATCH 3/9] patch calls to repond_to? to include protected methods when necessary --- .../lib/active_record/associations/association_proxy.rb | 2 +- activerecord/lib/active_record/autosave_association.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/associations/association_proxy.rb b/activerecord/lib/active_record/associations/association_proxy.rb index f925eb23fae98..56a25a92cd154 100644 --- a/activerecord/lib/active_record/associations/association_proxy.rb +++ b/activerecord/lib/active_record/associations/association_proxy.rb @@ -142,7 +142,7 @@ def inspect end def send(method, *args) - if proxy_respond_to?(method) + if proxy_respond_to?(method, true) super else load_target diff --git a/activerecord/lib/active_record/autosave_association.rb b/activerecord/lib/active_record/autosave_association.rb index 045e16b03f7fc..13333750f6ddc 100644 --- a/activerecord/lib/active_record/autosave_association.rb +++ b/activerecord/lib/active_record/autosave_association.rb @@ -331,7 +331,7 @@ def save_collection_association(reflection) end # reconstruct the SQL queries now that we know the owner's id - association.send(:construct_sql) if association.respond_to?(:construct_sql) + association.send(:construct_sql) if association.respond_to?(:construct_sql, true) end end From 3733cf7b1efdac2c295a11b7d835ea7a8f340d4a Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Thu, 3 Nov 2016 12:31:42 -0700 Subject: [PATCH 4/9] Add protected methods to respond_to? call in AR callbacks --- activerecord/lib/active_record/callbacks.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index e375037b5b09e..d055331332561 100644 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -343,7 +343,7 @@ def destroy_with_callbacks #:nodoc: def callback(method) result = run_callbacks(method) { |result, object| false == result } - if result != false && respond_to_without_attributes?(method) + if result != false && respond_to_without_attributes?(method, true) result = send(method) end From abaab8b742fda941ec60704a49d1e695fd821fef Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Thu, 3 Nov 2016 12:37:18 -0700 Subject: [PATCH 5/9] Fix html escaping to use native XML escaping (https://github.com/rails/rails/pull/5312/files) --- .../core_ext/string/output_safety.rb | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index f3a8e5cb35eed..343a696e0f82d 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -5,21 +5,42 @@ module Util HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } JSON_ESCAPE = { '&' => '\u0026', '>' => '\u003E', '<' => '\u003C' } - # A utility method for escaping HTML tag characters. - # This method is also aliased as h. - # - # In your ERB templates, use this method to escape any unsafe content. For example: - # <%=h @person.name %> - # - # ==== Example: - # puts html_escape("is a > 0 & a < 10?") - # # => is a > 0 & a < 10? - def html_escape(s) - s = s.to_s - if s.html_safe? - s - else - s.gsub(/[&"'><]/n) { |special| HTML_ESCAPE[special] }.html_safe + # Detect whether 1.9 can transcode with XML escaping. + if '"><&""' == ('><&"'.encode('utf-8', :xml => :attr) rescue false) + # A utility method for escaping HTML tag characters. + # This method is also aliased as h. + # + # In your ERB templates, use this method to escape any unsafe content. For example: + # <%=h @person.name %> + # + # ==== Example: + # puts html_escape("is a > 0 & a < 10?") + # # => is a > 0 & a < 10? + def html_escape(s) + s = s.to_s + if s.html_safe? + s + else + s.encode(s.encoding, :xml => :attr)[1...-1].html_safe + end + end + else + # A utility method for escaping HTML tag characters. + # This method is also aliased as h. + # + # In your ERB templates, use this method to escape any unsafe content. For example: + # <%=h @person.name %> + # + # ==== Example: + # puts html_escape("is a > 0 & a < 10?") + # # => is a > 0 & a < 10? + def html_escape(s) + s = s.to_s + if s.html_safe? + s + else + s.gsub(/[&"><]/n) { |special| HTML_ESCAPE[special] }.html_safe + end end end From b920b3fe83500727557d15ef9d3ea9c9b3378bd2 Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Thu, 3 Nov 2016 12:55:11 -0700 Subject: [PATCH 6/9] Fix use of eval in rails generator --- railties/lib/rails_generator/commands.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index b684dc92bed7a..bfe87dd2f88f3 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -299,7 +299,7 @@ def template(relative_source, relative_destination, template_options = {}) # Evaluate any assignments in a temporary, throwaway binding. vars = template_options[:assigns] || {} b = template_options[:binding] || binding - vars.each { |k,v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b } + vars.each { |k, v| b.local_variable_set(:"#{k}", v) } # Render the source file with the temporary binding. ERB.new(file.read, nil, '-').result(b) From b076bc9f965df80909a5ea8ddc09bf495b5029d4 Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Thu, 3 Nov 2016 13:00:06 -0700 Subject: [PATCH 7/9] Force encode parameters to utf-8 --- actionpack/lib/action_controller/request.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 4b1922024d08b..2c8744aa58361 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -494,6 +494,7 @@ def normalize_parameters(value) when Array value.map { |e| normalize_parameters(e) } else + value.force_encoding(Encoding.default_external) if value.respond_to?(:force_encoding) value end end From abb12eb6bdb96fe52d9a16131a586c709dad8aab Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Thu, 3 Nov 2016 13:02:30 -0700 Subject: [PATCH 8/9] Make declarative testing work with ruby 2+ --- .../lib/active_support/testing/declarative.rb | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/activesupport/lib/active_support/testing/declarative.rb b/activesupport/lib/active_support/testing/declarative.rb index cb6a5844ebc76..a3d7ddee87a8a 100644 --- a/activesupport/lib/active_support/testing/declarative.rb +++ b/activesupport/lib/active_support/testing/declarative.rb @@ -1,18 +1,20 @@ module ActiveSupport module Testing module Declarative - # test "verify something" do - # ... - # end - def test(name, &block) - test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym - defined = instance_method(test_name) rescue false - raise "#{test_name} is already defined in #{self}" if defined - if block_given? - define_method(test_name, &block) - else - define_method(test_name) do - flunk "No implementation provided for #{name}" + unless defined?(Spec) + # test "verify something" do + # ... + # end + def test(name, &block) + test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym + defined = method_defined? test_name + raise "#{test_name} is already defined in #{self}" if defined + if block_given? + define_method(test_name, &block) + else + define_method(test_name) do + flunk "No implementation provided for #{name}" + end end end end From 39252fa3bd797161256c9b0a9b3fddacf75ac7f5 Mon Sep 17 00:00:00 2001 From: "mark.martin" Date: Tue, 8 Nov 2016 09:07:47 -0800 Subject: [PATCH 9/9] Attempt to just remove the vendor gem index --- railties/lib/rails/gem_dependency.rb | 20 +++----------------- railties/lib/tasks/framework.rake | 4 ++-- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb index 1ff608a8c0cbe..c00178fc769f5 100644 --- a/railties/lib/rails/gem_dependency.rb +++ b/railties/lib/rails/gem_dependency.rb @@ -1,11 +1,5 @@ require 'rails/vendor_gem_source_index' -module Gem - def self.source_index=(index) - @@source_index = index - end -end - module Rails class GemDependency < Gem::Dependency attr_accessor :lib, :source, :dep @@ -18,10 +12,6 @@ def self.unpacked_path def self.add_frozen_gem_path @@paths_loaded ||= begin - source_index = Rails::VendorGemSourceIndex.new(Gem.source_index) - Gem.clear_paths - Gem.source_index = source_index - # loaded before us - we can't change them, so mark them Gem.loaded_specs.each do |name, spec| @@framework_gems[name] = spec end @@ -74,8 +64,7 @@ def add_load_paths end begin - dep = Gem::Dependency.new(name, requirement) - spec = Gem.source_index.find { |_,s| s.satisfies_requirement?(dep) }.last + spec = Gem::Specification.find_all_by_name(name, requirement).last spec.activate # a way that exists rescue gem self.name, self.requirement # < 1.8 unhappy way @@ -101,7 +90,7 @@ def specification # code repeated from Gem.activate. Find a matching spec, or the currently loaded version. # error out if loaded version and requested version are incompatible. @spec ||= begin - matches = Gem.source_index.search(self) + matches = Gem::Specification.find_all_by_name(self.name) matches << @@framework_gems[name] if framework_gem? if Gem.loaded_specs[name] then # This gem is already loaded. If the currently loaded gem is not in the @@ -218,10 +207,7 @@ def load end def refresh - Rails::VendorGemSourceIndex.silence_spec_warnings = true - real_gems = Gem.source_index.installed_source_index - exact_dep = Gem::Dependency.new(name, "= #{specification.version}") - matches = real_gems.search(exact_dep) + matches = Gem::Specification.find_all_by_name(name, "= #{specification.version}") installed_spec = matches.first if frozen? if installed_spec diff --git a/railties/lib/tasks/framework.rake b/railties/lib/tasks/framework.rake index 7a375962822d2..3385082fe3e56 100644 --- a/railties/lib/tasks/framework.rake +++ b/railties/lib/tasks/framework.rake @@ -7,8 +7,8 @@ namespace :rails do require 'rubygems/gem_runner' rails = (version = ENV['VERSION']) ? - Gem.cache.find_name('rails', "= #{version}").first : - Gem.cache.find_name('rails').sort_by { |g| g.version }.last + Gem::Specification.find_by_name('rails', "= #{version}") : + Gem::Specification.find_all_by_name('rails').sort_by { |g| g.version }.last version ||= rails.version