From 2f9e880431f7a53e470164203ea82be3d2d0ca3a Mon Sep 17 00:00:00 2001 From: Michael Koziarski Date: Mon, 18 Oct 2010 11:17:13 +1300 Subject: Rejig the html5 data helper code Avoid allocating an array each pass through and support String subclasses like SafeBuffers --- actionpack/lib/action_view/helpers/tag_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'actionpack/lib/action_view/helpers/tag_helper.rb') diff --git a/actionpack/lib/action_view/helpers/tag_helper.rb b/actionpack/lib/action_view/helpers/tag_helper.rb index b00b7636c3..48c65acace 100644 --- a/actionpack/lib/action_view/helpers/tag_helper.rb +++ b/actionpack/lib/action_view/helpers/tag_helper.rb @@ -127,9 +127,11 @@ module ActionView options.each_pair do |key, value| if key.to_s == 'data' && value.is_a?(Hash) value.each do |k, v| - final_v = [String, Symbol].include?(v.class) ? v : v.to_json - final_v = html_escape(final_v) if escape - attrs << %(data-#{k.to_s.dasherize}="#{final_v}") + if !v.is_a?(String) && !v.is_a?(Symbol) + v = v.to_json + end + v = html_escape(v) if escape + attrs << %(data-#{k.to_s.dasherize}="#{v}") end elsif BOOLEAN_ATTRIBUTES.include?(key) attrs << %(#{key}="#{key}") if value -- cgit v1.2.3