brakeman 4.10.1 → 5.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +9 -7
  3. data/README.md +1 -1
  4. data/bundle/load.rb +8 -9
  5. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/CHANGELOG.md +1 -8
  6. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/FAQ.md +0 -0
  7. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/Gemfile +0 -0
  8. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/MIT-LICENSE +0 -0
  9. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/README.md +0 -0
  10. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/REFERENCE.md +5 -9
  11. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/TODO +0 -0
  12. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/haml.gemspec +1 -1
  13. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml.rb +0 -0
  14. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/attribute_builder.rb +0 -0
  15. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/attribute_compiler.rb +0 -0
  16. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/attribute_parser.rb +0 -0
  17. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/buffer.rb +0 -0
  18. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/compiler.rb +0 -0
  19. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/engine.rb +0 -0
  20. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/error.rb +0 -0
  21. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/escapable.rb +0 -0
  22. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/exec.rb +0 -0
  23. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/filters.rb +0 -0
  24. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/generator.rb +0 -0
  25. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers.rb +0 -0
  26. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/action_view_extensions.rb +0 -0
  27. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/action_view_mods.rb +0 -0
  28. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/action_view_xss_mods.rb +0 -0
  29. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/safe_erubi_template.rb +0 -0
  30. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/safe_erubis_template.rb +0 -0
  31. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/helpers/xss_mods.rb +0 -0
  32. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/options.rb +0 -0
  33. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/parser.rb +3 -31
  34. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/plugin.rb +0 -0
  35. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/railtie.rb +0 -0
  36. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/sass_rails_filter.rb +0 -0
  37. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/template.rb +0 -0
  38. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/template/options.rb +0 -0
  39. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/temple_engine.rb +0 -0
  40. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/temple_line_counter.rb +0 -0
  41. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/util.rb +1 -1
  42. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/lib/haml/version.rb +1 -1
  43. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/yard/default/fulldoc/html/css/common.sass +0 -0
  44. data/bundle/ruby/2.7.0/gems/{haml-5.2.1 → haml-5.2.0}/yard/default/layout/html/footer.erb +0 -0
  45. data/lib/brakeman.rb +6 -0
  46. data/lib/brakeman/app_tree.rb +36 -3
  47. data/lib/brakeman/checks/check_execute.rb +1 -1
  48. data/lib/brakeman/checks/check_regex_dos.rb +1 -1
  49. data/lib/brakeman/checks/check_unsafe_reflection_methods.rb +68 -0
  50. data/lib/brakeman/checks/check_verb_confusion.rb +75 -0
  51. data/lib/brakeman/file_parser.rb +19 -23
  52. data/lib/brakeman/options.rb +5 -1
  53. data/lib/brakeman/parsers/template_parser.rb +2 -3
  54. data/lib/brakeman/processors/alias_processor.rb +2 -2
  55. data/lib/brakeman/processors/controller_processor.rb +1 -1
  56. data/lib/brakeman/processors/lib/file_type_detector.rb +64 -0
  57. data/lib/brakeman/processors/output_processor.rb +1 -1
  58. data/lib/brakeman/processors/template_alias_processor.rb +0 -5
  59. data/lib/brakeman/report.rb +8 -0
  60. data/lib/brakeman/report/report_sonar.rb +38 -0
  61. data/lib/brakeman/rescanner.rb +7 -5
  62. data/lib/brakeman/scanner.rb +42 -18
  63. data/lib/brakeman/tracker.rb +6 -0
  64. data/lib/brakeman/tracker/controller.rb +1 -1
  65. data/lib/brakeman/util.rb +9 -4
  66. data/lib/brakeman/version.rb +1 -1
  67. data/lib/brakeman/warning_codes.rb +2 -0
  68. data/lib/ruby_parser/bm_sexp.rb +9 -9
  69. metadata +49 -99
  70. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/Gemfile +0 -6
  71. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/LICENSE.txt +0 -22
  72. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/NEWS.md +0 -141
  73. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/README.md +0 -60
  74. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/attlistdecl.rb +0 -63
  75. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/attribute.rb +0 -205
  76. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/cdata.rb +0 -68
  77. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/child.rb +0 -97
  78. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/comment.rb +0 -80
  79. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/doctype.rb +0 -287
  80. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/document.rb +0 -291
  81. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/attlistdecl.rb +0 -11
  82. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/dtd.rb +0 -47
  83. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/elementdecl.rb +0 -18
  84. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/entitydecl.rb +0 -57
  85. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/notationdecl.rb +0 -40
  86. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/element.rb +0 -1269
  87. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/encoding.rb +0 -51
  88. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/entity.rb +0 -171
  89. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/default.rb +0 -116
  90. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/pretty.rb +0 -142
  91. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/transitive.rb +0 -58
  92. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/functions.rb +0 -447
  93. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/instruction.rb +0 -79
  94. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/light/node.rb +0 -196
  95. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb +0 -59
  96. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/node.rb +0 -76
  97. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/output.rb +0 -30
  98. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parent.rb +0 -166
  99. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parseexception.rb +0 -52
  100. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/baseparser.rb +0 -594
  101. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/lightparser.rb +0 -59
  102. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/pullparser.rb +0 -197
  103. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/sax2parser.rb +0 -273
  104. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/streamparser.rb +0 -61
  105. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/treeparser.rb +0 -101
  106. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/ultralightparser.rb +0 -57
  107. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/xpathparser.rb +0 -675
  108. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/quickpath.rb +0 -266
  109. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/rexml.rb +0 -32
  110. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/sax2listener.rb +0 -98
  111. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/security.rb +0 -28
  112. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/source.rb +0 -298
  113. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/streamlistener.rb +0 -93
  114. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/text.rb +0 -424
  115. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/undefinednamespaceexception.rb +0 -9
  116. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/relaxng.rb +0 -539
  117. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/validation.rb +0 -144
  118. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/validationexception.rb +0 -10
  119. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xmldecl.rb +0 -130
  120. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xmltokens.rb +0 -85
  121. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xpath.rb +0 -81
  122. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xpath_parser.rb +0 -968
  123. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/rexml.gemspec +0 -84
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- require_relative "child"
4
- require_relative "source"
5
-
6
- module REXML
7
- # Represents an XML Instruction; IE, <? ... ?>
8
- # TODO: Add parent arg (3rd arg) to constructor
9
- class Instruction < Child
10
- START = "<?"
11
- STOP = "?>"
12
-
13
- # target is the "name" of the Instruction; IE, the "tag" in <?tag ...?>
14
- # content is everything else.
15
- attr_accessor :target, :content
16
-
17
- # Constructs a new Instruction
18
- # @param target can be one of a number of things. If String, then
19
- # the target of this instruction is set to this. If an Instruction,
20
- # then the Instruction is shallowly cloned (target and content are
21
- # copied).
22
- # @param content Must be either a String, or a Parent. Can only
23
- # be a Parent if the target argument is a Source. Otherwise, this
24
- # String is set as the content of this instruction.
25
- def initialize(target, content=nil)
26
- case target
27
- when String
28
- super()
29
- @target = target
30
- @content = content
31
- when Instruction
32
- super(content)
33
- @target = target.target
34
- @content = target.content
35
- else
36
- message =
37
- "processing instruction target must be String or REXML::Instruction: "
38
- message << "<#{target.inspect}>"
39
- raise ArgumentError, message
40
- end
41
- @content.strip! if @content
42
- end
43
-
44
- def clone
45
- Instruction.new self
46
- end
47
-
48
- # == DEPRECATED
49
- # See the rexml/formatters package
50
- #
51
- def write writer, indent=-1, transitive=false, ie_hack=false
52
- Kernel.warn( "#{self.class.name}.write is deprecated", uplevel: 1)
53
- indent(writer, indent)
54
- writer << START
55
- writer << @target
56
- if @content
57
- writer << ' '
58
- writer << @content
59
- end
60
- writer << STOP
61
- end
62
-
63
- # @return true if other is an Instruction, and the content and target
64
- # of the other matches the target and content of this object.
65
- def ==( other )
66
- other.kind_of? Instruction and
67
- other.target == @target and
68
- other.content == @content
69
- end
70
-
71
- def node_type
72
- :processing_instruction
73
- end
74
-
75
- def inspect
76
- "<?p-i #{target} ...?>"
77
- end
78
- end
79
- end
@@ -1,196 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative '../xmltokens'
3
-
4
- # [ :element, parent, name, attributes, children* ]
5
- # a = Node.new
6
- # a << "B" # => <a>B</a>
7
- # a.b # => <a>B<b/></a>
8
- # a.b[1] # => <a>B<b/><b/><a>
9
- # a.b[1]["x"] = "y" # => <a>B<b/><b x="y"/></a>
10
- # a.b[0].c # => <a>B<b><c/></b><b x="y"/></a>
11
- # a.b.c << "D" # => <a>B<b><c>D</c></b><b x="y"/></a>
12
- module REXML
13
- module Light
14
- # Represents a tagged XML element. Elements are characterized by
15
- # having children, attributes, and names, and can themselves be
16
- # children.
17
- class Node
18
- NAMESPLIT = /^(?:(#{XMLTokens::NCNAME_STR}):)?(#{XMLTokens::NCNAME_STR})/u
19
- PARENTS = [ :element, :document, :doctype ]
20
- # Create a new element.
21
- def initialize node=nil
22
- @node = node
23
- if node.kind_of? String
24
- node = [ :text, node ]
25
- elsif node.nil?
26
- node = [ :document, nil, nil ]
27
- elsif node[0] == :start_element
28
- node[0] = :element
29
- elsif node[0] == :start_doctype
30
- node[0] = :doctype
31
- elsif node[0] == :start_document
32
- node[0] = :document
33
- end
34
- end
35
-
36
- def size
37
- if PARENTS.include? @node[0]
38
- @node[-1].size
39
- else
40
- 0
41
- end
42
- end
43
-
44
- def each
45
- size.times { |x| yield( at(x+4) ) }
46
- end
47
-
48
- def name
49
- at(2)
50
- end
51
-
52
- def name=( name_str, ns=nil )
53
- pfx = ''
54
- pfx = "#{prefix(ns)}:" if ns
55
- _old_put(2, "#{pfx}#{name_str}")
56
- end
57
-
58
- def parent=( node )
59
- _old_put(1,node)
60
- end
61
-
62
- def local_name
63
- namesplit
64
- @name
65
- end
66
-
67
- def local_name=( name_str )
68
- _old_put( 1, "#@prefix:#{name_str}" )
69
- end
70
-
71
- def prefix( namespace=nil )
72
- prefix_of( self, namespace )
73
- end
74
-
75
- def namespace( prefix=prefix() )
76
- namespace_of( self, prefix )
77
- end
78
-
79
- def namespace=( namespace )
80
- @prefix = prefix( namespace )
81
- pfx = ''
82
- pfx = "#@prefix:" if @prefix.size > 0
83
- _old_put(1, "#{pfx}#@name")
84
- end
85
-
86
- def []( reference, ns=nil )
87
- if reference.kind_of? String
88
- pfx = ''
89
- pfx = "#{prefix(ns)}:" if ns
90
- at(3)["#{pfx}#{reference}"]
91
- elsif reference.kind_of? Range
92
- _old_get( Range.new(4+reference.begin, reference.end, reference.exclude_end?) )
93
- else
94
- _old_get( 4+reference )
95
- end
96
- end
97
-
98
- def =~( path )
99
- XPath.match( self, path )
100
- end
101
-
102
- # Doesn't handle namespaces yet
103
- def []=( reference, ns, value=nil )
104
- if reference.kind_of? String
105
- value = ns unless value
106
- at( 3 )[reference] = value
107
- elsif reference.kind_of? Range
108
- _old_put( Range.new(3+reference.begin, reference.end, reference.exclude_end?), ns )
109
- else
110
- if value
111
- _old_put( 4+reference, ns, value )
112
- else
113
- _old_put( 4+reference, ns )
114
- end
115
- end
116
- end
117
-
118
- # Append a child to this element, optionally under a provided namespace.
119
- # The namespace argument is ignored if the element argument is an Element
120
- # object. Otherwise, the element argument is a string, the namespace (if
121
- # provided) is the namespace the element is created in.
122
- def << element
123
- if node_type() == :text
124
- at(-1) << element
125
- else
126
- newnode = Node.new( element )
127
- newnode.parent = self
128
- self.push( newnode )
129
- end
130
- at(-1)
131
- end
132
-
133
- def node_type
134
- _old_get(0)
135
- end
136
-
137
- def text=( foo )
138
- replace = at(4).kind_of?(String)? 1 : 0
139
- self._old_put(4,replace, normalizefoo)
140
- end
141
-
142
- def root
143
- context = self
144
- context = context.at(1) while context.at(1)
145
- end
146
-
147
- def has_name?( name, namespace = '' )
148
- at(3) == name and namespace() == namespace
149
- end
150
-
151
- def children
152
- self
153
- end
154
-
155
- def parent
156
- at(1)
157
- end
158
-
159
- def to_s
160
-
161
- end
162
-
163
- private
164
-
165
- def namesplit
166
- return if @name.defined?
167
- at(2) =~ NAMESPLIT
168
- @prefix = '' || $1
169
- @name = $2
170
- end
171
-
172
- def namespace_of( node, prefix=nil )
173
- if not prefix
174
- name = at(2)
175
- name =~ NAMESPLIT
176
- prefix = $1
177
- end
178
- to_find = 'xmlns'
179
- to_find = "xmlns:#{prefix}" if not prefix.nil?
180
- ns = at(3)[ to_find ]
181
- ns ? ns : namespace_of( @node[0], prefix )
182
- end
183
-
184
- def prefix_of( node, namespace=nil )
185
- if not namespace
186
- name = node.name
187
- name =~ NAMESPLIT
188
- $1
189
- else
190
- ns = at(3).find { |k,v| v == namespace }
191
- ns ? ns : prefix_of( node.parent, namespace )
192
- end
193
- end
194
- end
195
- end
196
- end
@@ -1,59 +0,0 @@
1
- # frozen_string_literal: false
2
-
3
- require_relative 'xmltokens'
4
-
5
- module REXML
6
- # Adds named attributes to an object.
7
- module Namespace
8
- # The name of the object, valid if set
9
- attr_reader :name, :expanded_name
10
- # The expanded name of the object, valid if name is set
11
- attr_accessor :prefix
12
- include XMLTokens
13
- NAMESPLIT = /^(?:(#{NCNAME_STR}):)?(#{NCNAME_STR})/u
14
-
15
- # Sets the name and the expanded name
16
- def name=( name )
17
- @expanded_name = name
18
- case name
19
- when NAMESPLIT
20
- if $1
21
- @prefix = $1
22
- else
23
- @prefix = ""
24
- @namespace = ""
25
- end
26
- @name = $2
27
- when ""
28
- @prefix = nil
29
- @namespace = nil
30
- @name = nil
31
- else
32
- message = "name must be \#{PREFIX}:\#{LOCAL_NAME} or \#{LOCAL_NAME}: "
33
- message += "<#{name.inspect}>"
34
- raise ArgumentError, message
35
- end
36
- end
37
-
38
- # Compares names optionally WITH namespaces
39
- def has_name?( other, ns=nil )
40
- if ns
41
- return (namespace() == ns and name() == other)
42
- elsif other.include? ":"
43
- return fully_expanded_name == other
44
- else
45
- return name == other
46
- end
47
- end
48
-
49
- alias :local_name :name
50
-
51
- # Fully expand the name, even if the prefix wasn't specified in the
52
- # source file.
53
- def fully_expanded_name
54
- ns = prefix
55
- return "#{ns}:#@name" if ns.size > 0
56
- return @name
57
- end
58
- end
59
- end
@@ -1,76 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative "parseexception"
3
- require_relative "formatters/pretty"
4
- require_relative "formatters/default"
5
-
6
- module REXML
7
- # Represents a node in the tree. Nodes are never encountered except as
8
- # superclasses of other objects. Nodes have siblings.
9
- module Node
10
- # @return the next sibling (nil if unset)
11
- def next_sibling_node
12
- return nil if @parent.nil?
13
- @parent[ @parent.index(self) + 1 ]
14
- end
15
-
16
- # @return the previous sibling (nil if unset)
17
- def previous_sibling_node
18
- return nil if @parent.nil?
19
- ind = @parent.index(self)
20
- return nil if ind == 0
21
- @parent[ ind - 1 ]
22
- end
23
-
24
- # indent::
25
- # *DEPRECATED* This parameter is now ignored. See the formatters in the
26
- # REXML::Formatters package for changing the output style.
27
- def to_s indent=nil
28
- unless indent.nil?
29
- Kernel.warn( "#{self.class.name}.to_s(indent) parameter is deprecated", uplevel: 1)
30
- f = REXML::Formatters::Pretty.new( indent )
31
- f.write( self, rv = "" )
32
- else
33
- f = REXML::Formatters::Default.new
34
- f.write( self, rv = "" )
35
- end
36
- return rv
37
- end
38
-
39
- def indent to, ind
40
- if @parent and @parent.context and not @parent.context[:indentstyle].nil? then
41
- indentstyle = @parent.context[:indentstyle]
42
- else
43
- indentstyle = ' '
44
- end
45
- to << indentstyle*ind unless ind<1
46
- end
47
-
48
- def parent?
49
- false;
50
- end
51
-
52
-
53
- # Visit all subnodes of +self+ recursively
54
- def each_recursive(&block) # :yields: node
55
- self.elements.each {|node|
56
- block.call(node)
57
- node.each_recursive(&block)
58
- }
59
- end
60
-
61
- # Find (and return) first subnode (recursively) for which the block
62
- # evaluates to true. Returns +nil+ if none was found.
63
- def find_first_recursive(&block) # :yields: node
64
- each_recursive {|node|
65
- return node if block.call(node)
66
- }
67
- return nil
68
- end
69
-
70
- # Returns the position that +self+ holds in its parent's array, indexed
71
- # from 1.
72
- def index_in_parent
73
- parent.index(self)+1
74
- end
75
- end
76
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative 'encoding'
3
-
4
- module REXML
5
- class Output
6
- include Encoding
7
-
8
- attr_reader :encoding
9
-
10
- def initialize real_IO, encd="iso-8859-1"
11
- @output = real_IO
12
- self.encoding = encd
13
-
14
- @to_utf = encoding != 'UTF-8'
15
-
16
- if encoding == "UTF-16"
17
- @output << "\ufeff".encode("UTF-16BE")
18
- self.encoding = "UTF-16BE"
19
- end
20
- end
21
-
22
- def <<( content )
23
- @output << (@to_utf ? self.encode(content) : content)
24
- end
25
-
26
- def to_s
27
- "Output[#{encoding}]"
28
- end
29
- end
30
- end
@@ -1,166 +0,0 @@
1
- # frozen_string_literal: false
2
- require_relative "child"
3
-
4
- module REXML
5
- # A parent has children, and has methods for accessing them. The Parent
6
- # class is never encountered except as the superclass for some other
7
- # object.
8
- class Parent < Child
9
- include Enumerable
10
-
11
- # Constructor
12
- # @param parent if supplied, will be set as the parent of this object
13
- def initialize parent=nil
14
- super(parent)
15
- @children = []
16
- end
17
-
18
- def add( object )
19
- object.parent = self
20
- @children << object
21
- object
22
- end
23
-
24
- alias :push :add
25
- alias :<< :push
26
-
27
- def unshift( object )
28
- object.parent = self
29
- @children.unshift object
30
- end
31
-
32
- def delete( object )
33
- found = false
34
- @children.delete_if {|c| c.equal?(object) and found = true }
35
- object.parent = nil if found
36
- found ? object : nil
37
- end
38
-
39
- def each(&block)
40
- @children.each(&block)
41
- end
42
-
43
- def delete_if( &block )
44
- @children.delete_if(&block)
45
- end
46
-
47
- def delete_at( index )
48
- @children.delete_at index
49
- end
50
-
51
- def each_index( &block )
52
- @children.each_index(&block)
53
- end
54
-
55
- # Fetches a child at a given index
56
- # @param index the Integer index of the child to fetch
57
- def []( index )
58
- @children[index]
59
- end
60
-
61
- alias :each_child :each
62
-
63
-
64
-
65
- # Set an index entry. See Array.[]=
66
- # @param index the index of the element to set
67
- # @param opt either the object to set, or an Integer length
68
- # @param child if opt is an Integer, this is the child to set
69
- # @return the parent (self)
70
- def []=( *args )
71
- args[-1].parent = self
72
- @children[*args[0..-2]] = args[-1]
73
- end
74
-
75
- # Inserts an child before another child
76
- # @param child1 this is either an xpath or an Element. If an Element,
77
- # child2 will be inserted before child1 in the child list of the parent.
78
- # If an xpath, child2 will be inserted before the first child to match
79
- # the xpath.
80
- # @param child2 the child to insert
81
- # @return the parent (self)
82
- def insert_before( child1, child2 )
83
- if child1.kind_of? String
84
- child1 = XPath.first( self, child1 )
85
- child1.parent.insert_before child1, child2
86
- else
87
- ind = index(child1)
88
- child2.parent.delete(child2) if child2.parent
89
- @children[ind,0] = child2
90
- child2.parent = self
91
- end
92
- self
93
- end
94
-
95
- # Inserts an child after another child
96
- # @param child1 this is either an xpath or an Element. If an Element,
97
- # child2 will be inserted after child1 in the child list of the parent.
98
- # If an xpath, child2 will be inserted after the first child to match
99
- # the xpath.
100
- # @param child2 the child to insert
101
- # @return the parent (self)
102
- def insert_after( child1, child2 )
103
- if child1.kind_of? String
104
- child1 = XPath.first( self, child1 )
105
- child1.parent.insert_after child1, child2
106
- else
107
- ind = index(child1)+1
108
- child2.parent.delete(child2) if child2.parent
109
- @children[ind,0] = child2
110
- child2.parent = self
111
- end
112
- self
113
- end
114
-
115
- def to_a
116
- @children.dup
117
- end
118
-
119
- # Fetches the index of a given child
120
- # @param child the child to get the index of
121
- # @return the index of the child, or nil if the object is not a child
122
- # of this parent.
123
- def index( child )
124
- count = -1
125
- @children.find { |i| count += 1 ; i.hash == child.hash }
126
- count
127
- end
128
-
129
- # @return the number of children of this parent
130
- def size
131
- @children.size
132
- end
133
-
134
- alias :length :size
135
-
136
- # Replaces one child with another, making sure the nodelist is correct
137
- # @param to_replace the child to replace (must be a Child)
138
- # @param replacement the child to insert into the nodelist (must be a
139
- # Child)
140
- def replace_child( to_replace, replacement )
141
- @children.map! {|c| c.equal?( to_replace ) ? replacement : c }
142
- to_replace.parent = nil
143
- replacement.parent = self
144
- end
145
-
146
- # Deeply clones this object. This creates a complete duplicate of this
147
- # Parent, including all descendants.
148
- def deep_clone
149
- cl = clone()
150
- each do |child|
151
- if child.kind_of? Parent
152
- cl << child.deep_clone
153
- else
154
- cl << child.clone
155
- end
156
- end
157
- cl
158
- end
159
-
160
- alias :children :to_a
161
-
162
- def parent?
163
- true
164
- end
165
- end
166
- end