rubysl-rexml 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/lib/rexml/attlistdecl.rb +56 -56
  4. data/lib/rexml/attribute.rb +155 -149
  5. data/lib/rexml/cdata.rb +48 -48
  6. data/lib/rexml/child.rb +82 -82
  7. data/lib/rexml/comment.rb +59 -59
  8. data/lib/rexml/doctype.rb +22 -24
  9. data/lib/rexml/document.rb +185 -129
  10. data/lib/rexml/dtd/attlistdecl.rb +7 -7
  11. data/lib/rexml/dtd/dtd.rb +41 -41
  12. data/lib/rexml/dtd/elementdecl.rb +13 -13
  13. data/lib/rexml/dtd/entitydecl.rb +49 -49
  14. data/lib/rexml/dtd/notationdecl.rb +32 -32
  15. data/lib/rexml/element.rb +122 -107
  16. data/lib/rexml/encoding.rb +37 -58
  17. data/lib/rexml/entity.rb +144 -144
  18. data/lib/rexml/formatters/default.rb +6 -4
  19. data/lib/rexml/formatters/pretty.rb +11 -8
  20. data/lib/rexml/formatters/transitive.rb +4 -3
  21. data/lib/rexml/functions.rb +33 -21
  22. data/lib/rexml/instruction.rb +49 -49
  23. data/lib/rexml/light/node.rb +190 -191
  24. data/lib/rexml/namespace.rb +39 -39
  25. data/lib/rexml/node.rb +38 -38
  26. data/lib/rexml/output.rb +17 -12
  27. data/lib/rexml/parent.rb +26 -25
  28. data/lib/rexml/parseexception.rb +4 -4
  29. data/lib/rexml/parsers/baseparser.rb +90 -61
  30. data/lib/rexml/parsers/lightparser.rb +41 -43
  31. data/lib/rexml/parsers/pullparser.rb +1 -1
  32. data/lib/rexml/parsers/sax2parser.rb +233 -198
  33. data/lib/rexml/parsers/streamparser.rb +6 -2
  34. data/lib/rexml/parsers/treeparser.rb +9 -6
  35. data/lib/rexml/parsers/ultralightparser.rb +40 -40
  36. data/lib/rexml/parsers/xpathparser.rb +51 -52
  37. data/lib/rexml/quickpath.rb +247 -248
  38. data/lib/rexml/rexml.rb +9 -10
  39. data/lib/rexml/sax2listener.rb +92 -92
  40. data/lib/rexml/security.rb +27 -0
  41. data/lib/rexml/source.rb +95 -50
  42. data/lib/rexml/streamlistener.rb +90 -90
  43. data/lib/rexml/syncenumerator.rb +3 -4
  44. data/lib/rexml/text.rb +157 -76
  45. data/lib/rexml/validation/relaxng.rb +18 -18
  46. data/lib/rexml/validation/validation.rb +5 -5
  47. data/lib/rexml/xmldecl.rb +59 -63
  48. data/lib/rexml/xmltokens.rb +14 -14
  49. data/lib/rexml/xpath.rb +67 -53
  50. data/lib/rexml/xpath_parser.rb +49 -38
  51. data/lib/rubysl/rexml.rb +1 -0
  52. data/lib/rubysl/rexml/version.rb +1 -1
  53. data/rubysl-rexml.gemspec +3 -1
  54. metadata +19 -28
  55. data/lib/rexml/encodings/CP-1252.rb +0 -103
  56. data/lib/rexml/encodings/EUC-JP.rb +0 -35
  57. data/lib/rexml/encodings/ICONV.rb +0 -22
  58. data/lib/rexml/encodings/ISO-8859-1.rb +0 -7
  59. data/lib/rexml/encodings/ISO-8859-15.rb +0 -72
  60. data/lib/rexml/encodings/SHIFT-JIS.rb +0 -37
  61. data/lib/rexml/encodings/SHIFT_JIS.rb +0 -1
  62. data/lib/rexml/encodings/UNILE.rb +0 -34
  63. data/lib/rexml/encodings/US-ASCII.rb +0 -30
  64. data/lib/rexml/encodings/UTF-16.rb +0 -35
  65. data/lib/rexml/encodings/UTF-8.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e77bc3d878fd21ec47c298c95206f0a123b0ecdd
4
- data.tar.gz: a737cd6cf7249364bb1d9e0b21f509440dbeefeb
3
+ metadata.gz: f2dcb560e63dac60be850a3109d1f5775b5847b2
4
+ data.tar.gz: 8e6659caa5224404cdeeb2c039dc051b2eeae6f0
5
5
  SHA512:
6
- metadata.gz: 8223bf80e756128360ce2d16e933e2a0d26c072e60f79a0eef1806711dbe375483a9680212390c7bb3dff1fe66a3aa4085ce5fc92729b6913937c79c8a89ebea
7
- data.tar.gz: 14b5508fa353ddb7ae50ba4d72c482f30f75d2e79595f5eea54ea0f5aecc9663811b323a9599d79e6af23772045e1c2bf24f320d9a8c028b5c73a8f4df3c1e64
6
+ metadata.gz: e5cab30fb1725a2107ab2fa15bf6027c7bfae1282105a74a09f1ca004b63a1d5f68c6351b1da78d5753e7935c6f40f9d82c06f5796820718d4cfeb054eb53ebe
7
+ data.tar.gz: edbd1a851942e68796deef805874ff3415b5fb8e67be7246e13477ab2f96bcf404d08310f37a1dfb32c1c0528b01ffce94f9fb485950bc147bca7081c5e08dc4
data/.travis.yml CHANGED
@@ -1,8 +1,9 @@
1
1
  language: ruby
2
2
  before_install:
3
+ - rvm use $RVM --install --binary --fuzzy
3
4
  - gem update --system
4
5
  - gem --version
5
6
  - gem install rubysl-bundler
7
+ env:
8
+ - RVM=rbx-nightly-d21 RUBYLIB=lib
6
9
  script: bundle exec mspec spec
7
- rvm:
8
- - rbx-nightly-18mode
@@ -3,60 +3,60 @@ require 'rexml/child'
3
3
  require 'rexml/source'
4
4
 
5
5
  module REXML
6
- # This class needs:
7
- # * Documentation
8
- # * Work! Not all types of attlists are intelligently parsed, so we just
9
- # spew back out what we get in. This works, but it would be better if
10
- # we formatted the output ourselves.
11
- #
12
- # AttlistDecls provide *just* enough support to allow namespace
13
- # declarations. If you need some sort of generalized support, or have an
14
- # interesting idea about how to map the hideous, terrible design of DTD
15
- # AttlistDecls onto an intuitive Ruby interface, let me know. I'm desperate
16
- # for anything to make DTDs more palateable.
17
- class AttlistDecl < Child
18
- include Enumerable
19
-
20
- # What is this? Got me.
21
- attr_reader :element_name
22
-
23
- # Create an AttlistDecl, pulling the information from a Source. Notice
24
- # that this isn't very convenient; to create an AttlistDecl, you basically
25
- # have to format it yourself, and then have the initializer parse it.
26
- # Sorry, but for the forseeable future, DTD support in REXML is pretty
27
- # weak on convenience. Have I mentioned how much I hate DTDs?
28
- def initialize(source)
29
- super()
30
- if (source.kind_of? Array)
31
- @element_name, @pairs, @contents = *source
32
- end
33
- end
34
-
35
- # Access the attlist attribute/value pairs.
36
- # value = attlist_decl[ attribute_name ]
37
- def [](key)
38
- @pairs[key]
39
- end
40
-
41
- # Whether an attlist declaration includes the given attribute definition
42
- # if attlist_decl.include? "xmlns:foobar"
43
- def include?(key)
44
- @pairs.keys.include? key
45
- end
46
-
47
- # Iterate over the key/value pairs:
48
- # attlist_decl.each { |attribute_name, attribute_value| ... }
49
- def each(&block)
50
- @pairs.each(&block)
51
- end
52
-
53
- # Write out exactly what we got in.
54
- def write out, indent=-1
55
- out << @contents
56
- end
57
-
58
- def node_type
59
- :attlistdecl
60
- end
61
- end
6
+ # This class needs:
7
+ # * Documentation
8
+ # * Work! Not all types of attlists are intelligently parsed, so we just
9
+ # spew back out what we get in. This works, but it would be better if
10
+ # we formatted the output ourselves.
11
+ #
12
+ # AttlistDecls provide *just* enough support to allow namespace
13
+ # declarations. If you need some sort of generalized support, or have an
14
+ # interesting idea about how to map the hideous, terrible design of DTD
15
+ # AttlistDecls onto an intuitive Ruby interface, let me know. I'm desperate
16
+ # for anything to make DTDs more palateable.
17
+ class AttlistDecl < Child
18
+ include Enumerable
19
+
20
+ # What is this? Got me.
21
+ attr_reader :element_name
22
+
23
+ # Create an AttlistDecl, pulling the information from a Source. Notice
24
+ # that this isn't very convenient; to create an AttlistDecl, you basically
25
+ # have to format it yourself, and then have the initializer parse it.
26
+ # Sorry, but for the forseeable future, DTD support in REXML is pretty
27
+ # weak on convenience. Have I mentioned how much I hate DTDs?
28
+ def initialize(source)
29
+ super()
30
+ if (source.kind_of? Array)
31
+ @element_name, @pairs, @contents = *source
32
+ end
33
+ end
34
+
35
+ # Access the attlist attribute/value pairs.
36
+ # value = attlist_decl[ attribute_name ]
37
+ def [](key)
38
+ @pairs[key]
39
+ end
40
+
41
+ # Whether an attlist declaration includes the given attribute definition
42
+ # if attlist_decl.include? "xmlns:foobar"
43
+ def include?(key)
44
+ @pairs.keys.include? key
45
+ end
46
+
47
+ # Iterate over the key/value pairs:
48
+ # attlist_decl.each { |attribute_name, attribute_value| ... }
49
+ def each(&block)
50
+ @pairs.each(&block)
51
+ end
52
+
53
+ # Write out exactly what we got in.
54
+ def write out, indent=-1
55
+ out << @contents
56
+ end
57
+
58
+ def node_type
59
+ :attlistdecl
60
+ end
61
+ end
62
62
  end
@@ -2,168 +2,174 @@ require "rexml/namespace"
2
2
  require 'rexml/text'
3
3
 
4
4
  module REXML
5
- # Defines an Element Attribute; IE, a attribute=value pair, as in:
6
- # <element attribute="value"/>. Attributes can be in their own
7
- # namespaces. General users of REXML will not interact with the
8
- # Attribute class much.
9
- class Attribute
10
- include Node
11
- include Namespace
12
-
13
- # The element to which this attribute belongs
14
- attr_reader :element
15
- # The normalized value of this attribute. That is, the attribute with
16
- # entities intact.
17
- attr_writer :normalized
18
- PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
19
-
20
- # Constructor.
5
+ # Defines an Element Attribute; IE, a attribute=value pair, as in:
6
+ # <element attribute="value"/>. Attributes can be in their own
7
+ # namespaces. General users of REXML will not interact with the
8
+ # Attribute class much.
9
+ class Attribute
10
+ include Node
11
+ include Namespace
12
+
13
+ # The element to which this attribute belongs
14
+ attr_reader :element
15
+ # The normalized value of this attribute. That is, the attribute with
16
+ # entities intact.
17
+ attr_writer :normalized
18
+ PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
19
+
20
+ NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um
21
+
22
+ # Constructor.
21
23
  # FIXME: The parser doesn't catch illegal characters in attributes
22
24
  #
23
- # first::
25
+ # first::
24
26
  # Either: an Attribute, which this new attribute will become a
25
27
  # clone of; or a String, which is the name of this attribute
26
28
  # second::
27
29
  # If +first+ is an Attribute, then this may be an Element, or nil.
28
30
  # If nil, then the Element parent of this attribute is the parent
29
- # of the +first+ Attribute. If the first argument is a String,
30
- # then this must also be a String, and is the content of the attribute.
31
+ # of the +first+ Attribute. If the first argument is a String,
32
+ # then this must also be a String, and is the content of the attribute.
31
33
  # If this is the content, it must be fully normalized (contain no
32
34
  # illegal characters).
33
35
  # parent::
34
- # Ignored unless +first+ is a String; otherwise, may be the Element
36
+ # Ignored unless +first+ is a String; otherwise, may be the Element
35
37
  # parent of this attribute, or nil.
36
38
  #
37
- #
38
- # Attribute.new( attribute_to_clone )
39
- # Attribute.new( attribute_to_clone, parent_element )
40
- # Attribute.new( "attr", "attr_value" )
41
- # Attribute.new( "attr", "attr_value", parent_element )
42
- def initialize( first, second=nil, parent=nil )
43
- @normalized = @unnormalized = @element = nil
44
- if first.kind_of? Attribute
45
- self.name = first.expanded_name
46
- @unnormalized = first.value
47
- if second.kind_of? Element
48
- @element = second
49
- else
50
- @element = first.element
51
- end
52
- elsif first.kind_of? String
53
- @element = parent
54
- self.name = first
55
- @normalized = second.to_s
56
- else
57
- raise "illegal argument #{first.class.name} to Attribute constructor"
58
- end
59
- end
60
-
61
- # Returns the namespace of the attribute.
62
- #
63
- # e = Element.new( "elns:myelement" )
64
- # e.add_attribute( "nsa:a", "aval" )
65
- # e.add_attribute( "b", "bval" )
66
- # e.attributes.get_attribute( "a" ).prefix # -> "nsa"
67
- # e.attributes.get_attribute( "b" ).prefix # -> "elns"
68
- # a = Attribute.new( "x", "y" )
69
- # a.prefix # -> ""
70
- def prefix
71
- pf = super
72
- if pf == ""
73
- pf = @element.prefix if @element
74
- end
75
- pf
76
- end
77
-
78
- # Returns the namespace URL, if defined, or nil otherwise
79
- #
80
- # e = Element.new("el")
81
- # e.add_attributes({"xmlns:ns", "http://url"})
82
- # e.namespace( "ns" ) # -> "http://url"
83
- def namespace arg=nil
84
- arg = prefix if arg.nil?
85
- @element.namespace arg
86
- end
87
-
88
- # Returns true if other is an Attribute and has the same name and value,
89
- # false otherwise.
90
- def ==( other )
91
- other.kind_of?(Attribute) and other.name==name and other.value==value
92
- end
93
-
94
- # Creates (and returns) a hash from both the name and value
95
- def hash
96
- name.hash + value.hash
97
- end
98
-
99
- # Returns this attribute out as XML source, expanding the name
100
- #
101
- # a = Attribute.new( "x", "y" )
102
- # a.to_string # -> "x='y'"
103
- # b = Attribute.new( "ns:x", "y" )
104
- # b.to_string # -> "ns:x='y'"
105
- def to_string
106
- if @element and @element.context and @element.context[:attribute_quote] == :quote
107
- %Q^#@expanded_name="#{to_s().gsub(/"/, '&quote;')}"^
108
- else
109
- "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
110
- end
111
- end
112
-
113
- # Returns the attribute value, with entities replaced
114
- def to_s
115
- return @normalized if @normalized
116
-
117
- doctype = nil
118
- if @element
119
- doc = @element.document
120
- doctype = doc.doctype if doc
121
- end
122
-
123
- @normalized = Text::normalize( @unnormalized, doctype )
124
- @unnormalized = nil
39
+ #
40
+ # Attribute.new( attribute_to_clone )
41
+ # Attribute.new( attribute_to_clone, parent_element )
42
+ # Attribute.new( "attr", "attr_value" )
43
+ # Attribute.new( "attr", "attr_value", parent_element )
44
+ def initialize( first, second=nil, parent=nil )
45
+ @normalized = @unnormalized = @element = nil
46
+ if first.kind_of? Attribute
47
+ self.name = first.expanded_name
48
+ @unnormalized = first.value
49
+ if second.kind_of? Element
50
+ @element = second
51
+ else
52
+ @element = first.element
53
+ end
54
+ elsif first.kind_of? String
55
+ @element = parent
56
+ self.name = first
57
+ @normalized = second.to_s
58
+ else
59
+ raise "illegal argument #{first.class.name} to Attribute constructor"
60
+ end
61
+ end
62
+
63
+ # Returns the namespace of the attribute.
64
+ #
65
+ # e = Element.new( "elns:myelement" )
66
+ # e.add_attribute( "nsa:a", "aval" )
67
+ # e.add_attribute( "b", "bval" )
68
+ # e.attributes.get_attribute( "a" ).prefix # -> "nsa"
69
+ # e.attributes.get_attribute( "b" ).prefix # -> "elns"
70
+ # a = Attribute.new( "x", "y" )
71
+ # a.prefix # -> ""
72
+ def prefix
73
+ pf = super
74
+ if pf == ""
75
+ pf = @element.prefix if @element
76
+ end
77
+ pf
78
+ end
79
+
80
+ # Returns the namespace URL, if defined, or nil otherwise
81
+ #
82
+ # e = Element.new("el")
83
+ # e.add_namespace("ns", "http://url")
84
+ # e.add_attribute("ns:a", "b")
85
+ # e.add_attribute("nsx:a", "c")
86
+ # e.attribute("ns:a").namespace # => "http://url"
87
+ # e.attribute("nsx:a").namespace # => nil
88
+ def namespace arg=nil
89
+ arg = prefix if arg.nil?
90
+ @element.namespace arg
91
+ end
92
+
93
+ # Returns true if other is an Attribute and has the same name and value,
94
+ # false otherwise.
95
+ def ==( other )
96
+ other.kind_of?(Attribute) and other.name==name and other.value==value
97
+ end
98
+
99
+ # Creates (and returns) a hash from both the name and value
100
+ def hash
101
+ name.hash + value.hash
102
+ end
103
+
104
+ # Returns this attribute out as XML source, expanding the name
105
+ #
106
+ # a = Attribute.new( "x", "y" )
107
+ # a.to_string # -> "x='y'"
108
+ # b = Attribute.new( "ns:x", "y" )
109
+ # b.to_string # -> "ns:x='y'"
110
+ def to_string
111
+ if @element and @element.context and @element.context[:attribute_quote] == :quote
112
+ %Q^#@expanded_name="#{to_s().gsub(/"/, '&quote;')}"^
113
+ else
114
+ "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
115
+ end
116
+ end
117
+
118
+ def doctype
119
+ if @element
120
+ doc = @element.document
121
+ doc.doctype if doc
122
+ end
123
+ end
124
+
125
+ # Returns the attribute value, with entities replaced
126
+ def to_s
127
+ return @normalized if @normalized
128
+
129
+ @normalized = Text::normalize( @unnormalized, doctype )
130
+ @unnormalized = nil
125
131
  @normalized
126
- end
127
-
128
- # Returns the UNNORMALIZED value of this attribute. That is, entities
129
- # have been expanded to their values
130
- def value
131
- return @unnormalized if @unnormalized
132
- doctype = nil
133
- if @element
134
- doc = @element.document
135
- doctype = doc.doctype if doc
136
- end
137
- @unnormalized = Text::unnormalize( @normalized, doctype )
138
- @normalized = nil
132
+ end
133
+
134
+ # Returns the UNNORMALIZED value of this attribute. That is, entities
135
+ # have been expanded to their values
136
+ def value
137
+ return @unnormalized if @unnormalized
138
+ @unnormalized = Text::unnormalize( @normalized, doctype )
139
+ @normalized = nil
139
140
  @unnormalized
140
- end
141
-
142
- # Returns a copy of this attribute
143
- def clone
144
- Attribute.new self
145
- end
146
-
147
- # Sets the element of which this object is an attribute. Normally, this
148
- # is not directly called.
149
- #
150
- # Returns this attribute
151
- def element=( element )
152
- @element = element
153
- self
154
- end
155
-
156
- # Removes this Attribute from the tree, and returns true if successfull
157
- #
158
- # This method is usually not called directly.
159
- def remove
160
- @element.attributes.delete self.name unless @element.nil?
161
- end
162
-
163
- # Writes this attribute (EG, puts 'key="value"' to the output)
164
- def write( output, indent=-1 )
165
- output << to_string
166
- end
141
+ end
142
+
143
+ # Returns a copy of this attribute
144
+ def clone
145
+ Attribute.new self
146
+ end
147
+
148
+ # Sets the element of which this object is an attribute. Normally, this
149
+ # is not directly called.
150
+ #
151
+ # Returns this attribute
152
+ def element=( element )
153
+ @element = element
154
+
155
+ if @normalized
156
+ Text.check( @normalized, NEEDS_A_SECOND_CHECK, doctype )
157
+ end
158
+
159
+ self
160
+ end
161
+
162
+ # Removes this Attribute from the tree, and returns true if successfull
163
+ #
164
+ # This method is usually not called directly.
165
+ def remove
166
+ @element.attributes.delete self.name unless @element.nil?
167
+ end
168
+
169
+ # Writes this attribute (EG, puts 'key="value"' to the output)
170
+ def write( output, indent=-1 )
171
+ output << to_string
172
+ end
167
173
 
168
174
  def node_type
169
175
  :attribute
@@ -180,6 +186,6 @@ module REXML
180
186
  path += "/@#{self.expanded_name}"
181
187
  return path
182
188
  end
183
- end
189
+ end
184
190
  end
185
191
  #vim:ts=2 sw=2 noexpandtab: