jordi-xml_struct 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/WHATSNEW CHANGED
@@ -1,3 +1,6 @@
1
+ * 0.2.1 (2008-10-13):
2
+ - Fixed a bug where attributes with dashes would crash the party
3
+
1
4
  * 0.2.0 (2008-10-13):
2
5
  - Broke backwards compatibility
3
6
  - XMLRecord.new now returns decorated String or Array objects, so that
data/lib/xml_struct.rb CHANGED
@@ -58,16 +58,24 @@ module XMLStruct
58
58
  children[key] = if children[key]
59
59
 
60
60
  unless obj.respond_to?((plural_key = key.to_s.pluralize).to_sym)
61
- obj.instance_eval %{
62
- def #{plural_key}; @__children[:#{key.to_s}]; end }
61
+ begin
62
+ obj.instance_eval %{
63
+ def #{plural_key}; @__children[%s|#{key.to_s}|]; end }
64
+ rescue SyntaxError
65
+ nil
66
+ end
63
67
  end
64
68
 
65
69
  children[key] = [ children[key] ] unless children[key].is_a? Array
66
70
  children[key] << element
67
71
  else
68
72
  unless obj.respond_to? key
69
- obj.instance_eval %{
70
- def #{key.to_s}; @__children[:#{key.to_s}]; end }
73
+ begin
74
+ obj.instance_eval %{
75
+ def #{key.to_s}; @__children[%s|#{key.to_s}|]; end }
76
+ rescue SyntaxError
77
+ nil
78
+ end
71
79
  end
72
80
 
73
81
  element
@@ -85,8 +93,12 @@ module XMLStruct
85
93
  attributes[(key = name.to_sym)] = attr_value.squish.extend String
86
94
 
87
95
  unless obj.respond_to? key
88
- obj.instance_eval %{
89
- def #{key.to_s}; @__attributes[:#{key.to_s}]; end }
96
+ begin
97
+ obj.instance_eval %{
98
+ def #{key.to_s}; @__attributes[%s|#{key.to_s}|]; end }
99
+ rescue SyntaxError
100
+ nil
101
+ end
90
102
  end
91
103
 
92
104
  obj.instance_variable_set :@__attributes, attributes
@@ -0,0 +1,2 @@
1
+ <weird attr-with-dashes="lame">
2
+ </weird>
data/test/test_helper.rb CHANGED
@@ -24,6 +24,7 @@ end
24
24
 
25
25
  require 'digest/md5'
26
26
  { :lorem => '9062c0f294383435d5b04ce6d67b6d61',
27
+ :weird_characters => 'cdcbd9b89b261487fa98c11d856f50fe',
27
28
  :recipe => '6087ab42049273d123d473093b04ab12' }.each do |file_key, md5|
28
29
 
29
30
  unless Digest::MD5.hexdigest(xml_file(file_key).read) == md5
@@ -1,5 +1,19 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
+ describe 'An XML file with weird characters' do
4
+
5
+ it 'should not raise exceptions' do
6
+ should.not.raise(Exception) do
7
+ @xml = XMLStruct.new xml_file(:weird_characters)
8
+ end
9
+ end
10
+
11
+ it 'should allow access to attributes with dashes in the name' do
12
+ XMLStruct.new(
13
+ xml_file(:weird_characters))['attr-with-dashes'].should == 'lame'
14
+ end
15
+ end
16
+
3
17
  describe 'The XML Struct module' do
4
18
 
5
19
  def setup
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jordi-xml_struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jordi Bunster
@@ -75,6 +75,7 @@ test_files:
75
75
  - test/samples
76
76
  - test/samples/lorem.xml
77
77
  - test/samples/recipe.xml
78
+ - test/samples/weird_characters.xml
78
79
  - test/test_helper.rb
79
80
  - test/vendor
80
81
  - test/vendor/test-spec