From 4f16f680a63523e0db3eda5340f569f9d220eae5 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Fri, 26 Jun 2009 17:18:28 +0900 Subject: [PATCH] Simplified regex for filtering non ASCII chars --- activesupport/lib/active_support/json/encoding.rb | 4 +--- 1 files changed, 1 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index 068b58b..c8255f3 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -96,9 +96,7 @@ module ActiveSupport def escape(string) string = string.dup.force_encoding(::Encoding::BINARY) if string.respond_to?(:force_encoding) json = '"' + string.gsub(escape_regex) { |s| ESCAPED_CHARS[s] } - json.gsub(/([\xC0-\xDF][\x80-\xBF]| - [\xE0-\xEF][\x80-\xBF]{2}| - [\xF0-\xF7][\x80-\xBF]{3})+/nx) { |s| + json.gsub(/[^\x00-\x7F]+/) { |s| s.unpack("U*").pack("n*").unpack("H*")[0].gsub(/.{4}/, '\\\\u\&') } + '"' end -- 1.6.3.3