OSDN Git Service

テスト時に大量発生するワーニングに対してモンキーパッチ
authorYOSHIDA Hiroki <hyoshida@appirits.com>
Fri, 31 May 2013 09:04:54 +0000 (18:04 +0900)
committerYOSHIDA Hiroki <hyoshida@appirits.com>
Fri, 31 May 2013 12:23:36 +0000 (21:23 +0900)
config/initializers/erb_util_silence.rb [new file with mode: 0644]

diff --git a/config/initializers/erb_util_silence.rb b/config/initializers/erb_util_silence.rb
new file mode 100644 (file)
index 0000000..c7ad138
--- /dev/null
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+if Rails::VERSION::MAJOR == 2
+  require "active_support/core_ext/string/output_safety"
+
+  class ERB
+    module Util
+      # see https://github.com/rails/rails/issues/7430
+      def html_escape(s)
+        s = s.to_s
+        if s.html_safe?
+          s
+        else
+          # 「invalid byte sequence in US-ASCII」対策
+          s = s.toutf8
+
+          s.gsub(/[&"'><]/, HTML_ESCAPE).html_safe
+        end
+      end
+
+      alias h html_escape
+
+      singleton_class.send(:remove_method, :html_escape)
+      module_function :html_escape, :h
+    end
+  end
+else
+  puts "You can delete this file+test now #{__FILE__}"
+end