aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/xml_mini.rb
diff options
context:
space:
mode:
authorBernerd Schaefer <bj.schaefer@gmail.com>2010-07-17 16:45:19 -0500
committerwycats <wycats@gmail.com>2010-07-26 09:48:22 -0700
commite87e3db200e5b711237da8bcdc873044a984ad90 (patch)
tree06aaa658f144528635854a2aeacbf3ce0c6f0364 /activesupport/lib/active_support/xml_mini.rb
parent4ea1753fc2bcbaca0a50073463ef4b020a2e3c5f (diff)
downloadrails-e87e3db200e5b711237da8bcdc873044a984ad90.tar.gz
rails-e87e3db200e5b711237da8bcdc873044a984ad90.tar.bz2
rails-e87e3db200e5b711237da8bcdc873044a984ad90.zip
XmlMini.rename_key emits valid xml with dasherize
This resolves issues for libraries which use '_' prefixed keys in their attributes hash, such as Mongoid. A key like "_id" or "_type" will no longer be converted to "<-id>" and "<-type>". Signed-off-by: wycats <wycats@gmail.com>
Diffstat (limited to 'activesupport/lib/active_support/xml_mini.rb')
-rw-r--r--activesupport/lib/active_support/xml_mini.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/xml_mini.rb b/activesupport/lib/active_support/xml_mini.rb
index 38e20d32da..352172027b 100644
--- a/activesupport/lib/active_support/xml_mini.rb
+++ b/activesupport/lib/active_support/xml_mini.rb
@@ -129,12 +129,16 @@ module ActiveSupport
camelize = options.has_key?(:camelize) && options[:camelize]
dasherize = !options.has_key?(:dasherize) || options[:dasherize]
key = key.camelize if camelize
- key = key.dasherize if dasherize
+ key = _dasherize(key) if dasherize
key
end
protected
+ def _dasherize(key)
+ key.gsub(/(?!^[_]*)_(?![_]*$)/, '-')
+ end
+
# TODO: Add support for other encodings
def _parse_binary(bin, entity) #:nodoc:
case entity['encoding']