brakeman 5.0.0.pre1 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +23 -0
  3. data/bundle/load.rb +9 -8
  4. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/CHANGELOG.md +8 -1
  5. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/FAQ.md +0 -0
  6. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/Gemfile +0 -0
  7. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/MIT-LICENSE +0 -0
  8. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/README.md +0 -0
  9. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/REFERENCE.md +9 -5
  10. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/TODO +0 -0
  11. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/haml.gemspec +1 -1
  12. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml.rb +0 -0
  13. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/attribute_builder.rb +0 -0
  14. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/attribute_compiler.rb +0 -0
  15. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/attribute_parser.rb +0 -0
  16. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/buffer.rb +0 -0
  17. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/compiler.rb +0 -0
  18. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/engine.rb +0 -0
  19. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/error.rb +0 -0
  20. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/escapable.rb +0 -0
  21. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/exec.rb +0 -0
  22. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/filters.rb +0 -0
  23. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/generator.rb +0 -0
  24. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers.rb +0 -0
  25. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/action_view_extensions.rb +0 -0
  26. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/action_view_mods.rb +0 -0
  27. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/action_view_xss_mods.rb +0 -0
  28. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/safe_erubi_template.rb +0 -0
  29. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/safe_erubis_template.rb +0 -0
  30. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/helpers/xss_mods.rb +0 -0
  31. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/options.rb +0 -0
  32. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/parser.rb +31 -3
  33. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/plugin.rb +0 -0
  34. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/railtie.rb +0 -0
  35. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/sass_rails_filter.rb +0 -0
  36. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/template.rb +0 -0
  37. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/template/options.rb +0 -0
  38. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/temple_engine.rb +0 -0
  39. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/temple_line_counter.rb +0 -0
  40. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/util.rb +1 -1
  41. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/lib/haml/version.rb +1 -1
  42. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/yard/default/fulldoc/html/css/common.sass +0 -0
  43. data/bundle/ruby/2.7.0/gems/{haml-5.2.0 → haml-5.2.1}/yard/default/layout/html/footer.erb +0 -0
  44. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/Gemfile +6 -0
  45. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/LICENSE.txt +22 -0
  46. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/NEWS.md +141 -0
  47. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/README.md +60 -0
  48. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/attlistdecl.rb +63 -0
  49. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/attribute.rb +205 -0
  50. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/cdata.rb +68 -0
  51. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/child.rb +97 -0
  52. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/comment.rb +80 -0
  53. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/doctype.rb +287 -0
  54. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/document.rb +291 -0
  55. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/attlistdecl.rb +11 -0
  56. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/dtd.rb +47 -0
  57. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/elementdecl.rb +18 -0
  58. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/entitydecl.rb +57 -0
  59. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/dtd/notationdecl.rb +40 -0
  60. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/element.rb +1269 -0
  61. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/encoding.rb +51 -0
  62. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/entity.rb +171 -0
  63. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/default.rb +116 -0
  64. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/pretty.rb +142 -0
  65. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/formatters/transitive.rb +58 -0
  66. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/functions.rb +447 -0
  67. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/instruction.rb +79 -0
  68. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/light/node.rb +196 -0
  69. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/namespace.rb +59 -0
  70. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/node.rb +76 -0
  71. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/output.rb +30 -0
  72. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parent.rb +166 -0
  73. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parseexception.rb +52 -0
  74. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/baseparser.rb +594 -0
  75. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/lightparser.rb +59 -0
  76. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/pullparser.rb +197 -0
  77. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/sax2parser.rb +273 -0
  78. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/streamparser.rb +61 -0
  79. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/treeparser.rb +101 -0
  80. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/ultralightparser.rb +57 -0
  81. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/parsers/xpathparser.rb +675 -0
  82. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/quickpath.rb +266 -0
  83. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/rexml.rb +32 -0
  84. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/sax2listener.rb +98 -0
  85. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/security.rb +28 -0
  86. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/source.rb +298 -0
  87. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/streamlistener.rb +93 -0
  88. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/text.rb +424 -0
  89. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/undefinednamespaceexception.rb +9 -0
  90. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/relaxng.rb +539 -0
  91. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/validation.rb +144 -0
  92. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/validation/validationexception.rb +10 -0
  93. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xmldecl.rb +130 -0
  94. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xmltokens.rb +85 -0
  95. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xpath.rb +81 -0
  96. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/lib/rexml/xpath_parser.rb +968 -0
  97. data/bundle/ruby/2.7.0/gems/rexml-3.2.4/rexml.gemspec +84 -0
  98. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/History.rdoc +6 -0
  99. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/Manifest.txt +0 -0
  100. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/README.rdoc +0 -0
  101. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/compare/normalize.rb +0 -0
  102. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/debugging.md +0 -0
  103. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/rp_extensions.rb +0 -0
  104. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/rp_stringscanner.rb +0 -0
  105. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby20_parser.rb +0 -0
  106. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby20_parser.y +0 -0
  107. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby21_parser.rb +0 -0
  108. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby21_parser.y +0 -0
  109. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby22_parser.rb +0 -0
  110. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby22_parser.y +0 -0
  111. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby23_parser.rb +0 -0
  112. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby23_parser.y +0 -0
  113. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby24_parser.rb +0 -0
  114. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby24_parser.y +0 -0
  115. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby25_parser.rb +0 -0
  116. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby25_parser.y +0 -0
  117. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby26_parser.rb +0 -0
  118. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby26_parser.y +0 -0
  119. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby27_parser.rb +0 -0
  120. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby27_parser.y +0 -0
  121. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_lexer.rb +0 -0
  122. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_lexer.rex +0 -0
  123. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_lexer.rex.rb +0 -0
  124. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_parser.rb +0 -0
  125. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_parser.yy +0 -0
  126. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/lib/ruby_parser_extras.rb +1 -1
  127. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/tools/munge.rb +0 -0
  128. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.15.1}/tools/ripper.rb +0 -0
  129. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/History.rdoc +6 -0
  130. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/Manifest.txt +0 -0
  131. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/README.rdoc +0 -0
  132. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/composite_sexp_processor.rb +0 -0
  133. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/pt_testcase.rb +0 -0
  134. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/sexp.rb +0 -0
  135. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/sexp_matcher.rb +0 -0
  136. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/sexp_processor.rb +1 -1
  137. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/strict_sexp.rb +0 -0
  138. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.2}/lib/unique.rb +0 -0
  139. data/lib/brakeman/checks/base_check.rb +7 -1
  140. data/lib/brakeman/checks/check_execute.rb +2 -1
  141. data/lib/brakeman/checks/check_regex_dos.rb +1 -1
  142. data/lib/brakeman/checks/check_sql.rb +1 -1
  143. data/lib/brakeman/file_parser.rb +5 -0
  144. data/lib/brakeman/processors/alias_processor.rb +20 -4
  145. data/lib/brakeman/processors/controller_processor.rb +1 -1
  146. data/lib/brakeman/processors/lib/rails3_config_processor.rb +16 -16
  147. data/lib/brakeman/processors/output_processor.rb +1 -1
  148. data/lib/brakeman/processors/template_alias_processor.rb +5 -0
  149. data/lib/brakeman/report/report_base.rb +0 -2
  150. data/lib/brakeman/report/report_csv.rb +37 -60
  151. data/lib/brakeman/report/report_junit.rb +2 -2
  152. data/lib/brakeman/report/report_sarif.rb +1 -1
  153. data/lib/brakeman/report/report_tabs.rb +1 -1
  154. data/lib/brakeman/report/report_text.rb +1 -1
  155. data/lib/brakeman/scanner.rb +3 -1
  156. data/lib/brakeman/tracker/config.rb +73 -0
  157. data/lib/brakeman/tracker/controller.rb +1 -1
  158. data/lib/brakeman/util.rb +2 -2
  159. data/lib/brakeman/version.rb +1 -1
  160. data/lib/brakeman/warning.rb +10 -2
  161. data/lib/ruby_parser/bm_sexp.rb +9 -9
  162. metadata +139 -85
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: false
2
+ #vim:ts=2 sw=2 noexpandtab:
3
+ require_relative 'child'
4
+ require_relative 'source'
5
+
6
+ module REXML
7
+ # This class needs:
8
+ # * Documentation
9
+ # * Work! Not all types of attlists are intelligently parsed, so we just
10
+ # spew back out what we get in. This works, but it would be better if
11
+ # we formatted the output ourselves.
12
+ #
13
+ # AttlistDecls provide *just* enough support to allow namespace
14
+ # declarations. If you need some sort of generalized support, or have an
15
+ # interesting idea about how to map the hideous, terrible design of DTD
16
+ # AttlistDecls onto an intuitive Ruby interface, let me know. I'm desperate
17
+ # for anything to make DTDs more palateable.
18
+ class AttlistDecl < Child
19
+ include Enumerable
20
+
21
+ # What is this? Got me.
22
+ attr_reader :element_name
23
+
24
+ # Create an AttlistDecl, pulling the information from a Source. Notice
25
+ # that this isn't very convenient; to create an AttlistDecl, you basically
26
+ # have to format it yourself, and then have the initializer parse it.
27
+ # Sorry, but for the foreseeable future, DTD support in REXML is pretty
28
+ # weak on convenience. Have I mentioned how much I hate DTDs?
29
+ def initialize(source)
30
+ super()
31
+ if (source.kind_of? Array)
32
+ @element_name, @pairs, @contents = *source
33
+ end
34
+ end
35
+
36
+ # Access the attlist attribute/value pairs.
37
+ # value = attlist_decl[ attribute_name ]
38
+ def [](key)
39
+ @pairs[key]
40
+ end
41
+
42
+ # Whether an attlist declaration includes the given attribute definition
43
+ # if attlist_decl.include? "xmlns:foobar"
44
+ def include?(key)
45
+ @pairs.keys.include? key
46
+ end
47
+
48
+ # Iterate over the key/value pairs:
49
+ # attlist_decl.each { |attribute_name, attribute_value| ... }
50
+ def each(&block)
51
+ @pairs.each(&block)
52
+ end
53
+
54
+ # Write out exactly what we got in.
55
+ def write out, indent=-1
56
+ out << @contents
57
+ end
58
+
59
+ def node_type
60
+ :attlistdecl
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,205 @@
1
+ # frozen_string_literal: false
2
+ require_relative "namespace"
3
+ require_relative 'text'
4
+
5
+ module REXML
6
+ # Defines an Element Attribute; IE, a attribute=value pair, as in:
7
+ # <element attribute="value"/>. Attributes can be in their own
8
+ # namespaces. General users of REXML will not interact with the
9
+ # Attribute class much.
10
+ class Attribute
11
+ include Node
12
+ include Namespace
13
+
14
+ # The element to which this attribute belongs
15
+ attr_reader :element
16
+ # The normalized value of this attribute. That is, the attribute with
17
+ # entities intact.
18
+ attr_writer :normalized
19
+ PATTERN = /\s*(#{NAME_STR})\s*=\s*(["'])(.*?)\2/um
20
+
21
+ NEEDS_A_SECOND_CHECK = /(<|&((#{Entity::NAME});|(#0*((?:\d+)|(?:x[a-fA-F0-9]+)));)?)/um
22
+
23
+ # Constructor.
24
+ # FIXME: The parser doesn't catch illegal characters in attributes
25
+ #
26
+ # first::
27
+ # Either: an Attribute, which this new attribute will become a
28
+ # clone of; or a String, which is the name of this attribute
29
+ # second::
30
+ # If +first+ is an Attribute, then this may be an Element, or nil.
31
+ # If nil, then the Element parent of this attribute is the parent
32
+ # of the +first+ Attribute. If the first argument is a String,
33
+ # then this must also be a String, and is the content of the attribute.
34
+ # If this is the content, it must be fully normalized (contain no
35
+ # illegal characters).
36
+ # parent::
37
+ # Ignored unless +first+ is a String; otherwise, may be the Element
38
+ # parent of this attribute, or nil.
39
+ #
40
+ #
41
+ # Attribute.new( attribute_to_clone )
42
+ # Attribute.new( attribute_to_clone, parent_element )
43
+ # Attribute.new( "attr", "attr_value" )
44
+ # Attribute.new( "attr", "attr_value", parent_element )
45
+ def initialize( first, second=nil, parent=nil )
46
+ @normalized = @unnormalized = @element = nil
47
+ if first.kind_of? Attribute
48
+ self.name = first.expanded_name
49
+ @unnormalized = first.value
50
+ if second.kind_of? Element
51
+ @element = second
52
+ else
53
+ @element = first.element
54
+ end
55
+ elsif first.kind_of? String
56
+ @element = parent
57
+ self.name = first
58
+ @normalized = second.to_s
59
+ else
60
+ raise "illegal argument #{first.class.name} to Attribute constructor"
61
+ end
62
+ end
63
+
64
+ # Returns the namespace of the attribute.
65
+ #
66
+ # e = Element.new( "elns:myelement" )
67
+ # e.add_attribute( "nsa:a", "aval" )
68
+ # e.add_attribute( "b", "bval" )
69
+ # e.attributes.get_attribute( "a" ).prefix # -> "nsa"
70
+ # e.attributes.get_attribute( "b" ).prefix # -> ""
71
+ # a = Attribute.new( "x", "y" )
72
+ # a.prefix # -> ""
73
+ def prefix
74
+ super
75
+ end
76
+
77
+ # Returns the namespace URL, if defined, or nil otherwise
78
+ #
79
+ # e = Element.new("el")
80
+ # e.add_namespace("ns", "http://url")
81
+ # e.add_attribute("ns:a", "b")
82
+ # e.add_attribute("nsx:a", "c")
83
+ # e.attribute("ns:a").namespace # => "http://url"
84
+ # e.attribute("nsx:a").namespace # => nil
85
+ #
86
+ # This method always returns "" for no namespace attribute. Because
87
+ # the default namespace doesn't apply to attribute names.
88
+ #
89
+ # From https://www.w3.org/TR/xml-names/#uniqAttrs
90
+ #
91
+ # > the default namespace does not apply to attribute names
92
+ #
93
+ # e = REXML::Element.new("el")
94
+ # e.add_namespace("", "http://example.com/")
95
+ # e.namespace # => "http://example.com/"
96
+ # e.add_attribute("a", "b")
97
+ # e.attribute("a").namespace # => ""
98
+ def namespace arg=nil
99
+ arg = prefix if arg.nil?
100
+ if arg == ""
101
+ ""
102
+ else
103
+ @element.namespace(arg)
104
+ end
105
+ end
106
+
107
+ # Returns true if other is an Attribute and has the same name and value,
108
+ # false otherwise.
109
+ def ==( other )
110
+ other.kind_of?(Attribute) and other.name==name and other.value==value
111
+ end
112
+
113
+ # Creates (and returns) a hash from both the name and value
114
+ def hash
115
+ name.hash + value.hash
116
+ end
117
+
118
+ # Returns this attribute out as XML source, expanding the name
119
+ #
120
+ # a = Attribute.new( "x", "y" )
121
+ # a.to_string # -> "x='y'"
122
+ # b = Attribute.new( "ns:x", "y" )
123
+ # b.to_string # -> "ns:x='y'"
124
+ def to_string
125
+ if @element and @element.context and @element.context[:attribute_quote] == :quote
126
+ %Q^#@expanded_name="#{to_s().gsub(/"/, '&quot;')}"^
127
+ else
128
+ "#@expanded_name='#{to_s().gsub(/'/, '&apos;')}'"
129
+ end
130
+ end
131
+
132
+ def doctype
133
+ if @element
134
+ doc = @element.document
135
+ doc.doctype if doc
136
+ end
137
+ end
138
+
139
+ # Returns the attribute value, with entities replaced
140
+ def to_s
141
+ return @normalized if @normalized
142
+
143
+ @normalized = Text::normalize( @unnormalized, doctype )
144
+ @unnormalized = nil
145
+ @normalized
146
+ end
147
+
148
+ # Returns the UNNORMALIZED value of this attribute. That is, entities
149
+ # have been expanded to their values
150
+ def value
151
+ return @unnormalized if @unnormalized
152
+ @unnormalized = Text::unnormalize( @normalized, doctype )
153
+ @normalized = nil
154
+ @unnormalized
155
+ end
156
+
157
+ # Returns a copy of this attribute
158
+ def clone
159
+ Attribute.new self
160
+ end
161
+
162
+ # Sets the element of which this object is an attribute. Normally, this
163
+ # is not directly called.
164
+ #
165
+ # Returns this attribute
166
+ def element=( element )
167
+ @element = element
168
+
169
+ if @normalized
170
+ Text.check( @normalized, NEEDS_A_SECOND_CHECK, doctype )
171
+ end
172
+
173
+ self
174
+ end
175
+
176
+ # Removes this Attribute from the tree, and returns true if successful
177
+ #
178
+ # This method is usually not called directly.
179
+ def remove
180
+ @element.attributes.delete self.name unless @element.nil?
181
+ end
182
+
183
+ # Writes this attribute (EG, puts 'key="value"' to the output)
184
+ def write( output, indent=-1 )
185
+ output << to_string
186
+ end
187
+
188
+ def node_type
189
+ :attribute
190
+ end
191
+
192
+ def inspect
193
+ rv = ""
194
+ write( rv )
195
+ rv
196
+ end
197
+
198
+ def xpath
199
+ path = @element.xpath
200
+ path += "/@#{self.expanded_name}"
201
+ return path
202
+ end
203
+ end
204
+ end
205
+ #vim:ts=2 sw=2 noexpandtab:
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: false
2
+ require_relative "text"
3
+
4
+ module REXML
5
+ class CData < Text
6
+ START = '<![CDATA['
7
+ STOP = ']]>'
8
+ ILLEGAL = /(\]\]>)/
9
+
10
+ # Constructor. CData is data between <![CDATA[ ... ]]>
11
+ #
12
+ # _Examples_
13
+ # CData.new( source )
14
+ # CData.new( "Here is some CDATA" )
15
+ # CData.new( "Some unprocessed data", respect_whitespace_TF, parent_element )
16
+ def initialize( first, whitespace=true, parent=nil )
17
+ super( first, whitespace, parent, false, true, ILLEGAL )
18
+ end
19
+
20
+ # Make a copy of this object
21
+ #
22
+ # _Examples_
23
+ # c = CData.new( "Some text" )
24
+ # d = c.clone
25
+ # d.to_s # -> "Some text"
26
+ def clone
27
+ CData.new self
28
+ end
29
+
30
+ # Returns the content of this CData object
31
+ #
32
+ # _Examples_
33
+ # c = CData.new( "Some text" )
34
+ # c.to_s # -> "Some text"
35
+ def to_s
36
+ @string
37
+ end
38
+
39
+ def value
40
+ @string
41
+ end
42
+
43
+ # == DEPRECATED
44
+ # See the rexml/formatters package
45
+ #
46
+ # Generates XML output of this object
47
+ #
48
+ # output::
49
+ # Where to write the string. Defaults to $stdout
50
+ # indent::
51
+ # The amount to indent this node by
52
+ # transitive::
53
+ # Ignored
54
+ # ie_hack::
55
+ # Ignored
56
+ #
57
+ # _Examples_
58
+ # c = CData.new( " Some text " )
59
+ # c.write( $stdout ) #-> <![CDATA[ Some text ]]>
60
+ def write( output=$stdout, indent=-1, transitive=false, ie_hack=false )
61
+ Kernel.warn( "#{self.class.name}.write is deprecated", uplevel: 1)
62
+ indent( output, indent )
63
+ output << START
64
+ output << @string
65
+ output << STOP
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: false
2
+ require_relative "node"
3
+
4
+ module REXML
5
+ ##
6
+ # A Child object is something contained by a parent, and this class
7
+ # contains methods to support that. Most user code will not use this
8
+ # class directly.
9
+ class Child
10
+ include Node
11
+ attr_reader :parent # The Parent of this object
12
+
13
+ # Constructor. Any inheritors of this class should call super to make
14
+ # sure this method is called.
15
+ # parent::
16
+ # if supplied, the parent of this child will be set to the
17
+ # supplied value, and self will be added to the parent
18
+ def initialize( parent = nil )
19
+ @parent = nil
20
+ # Declare @parent, but don't define it. The next line sets the
21
+ # parent.
22
+ parent.add( self ) if parent
23
+ end
24
+
25
+ # Replaces this object with another object. Basically, calls
26
+ # Parent.replace_child
27
+ #
28
+ # Returns:: self
29
+ def replace_with( child )
30
+ @parent.replace_child( self, child )
31
+ self
32
+ end
33
+
34
+ # Removes this child from the parent.
35
+ #
36
+ # Returns:: self
37
+ def remove
38
+ unless @parent.nil?
39
+ @parent.delete self
40
+ end
41
+ self
42
+ end
43
+
44
+ # Sets the parent of this child to the supplied argument.
45
+ #
46
+ # other::
47
+ # Must be a Parent object. If this object is the same object as the
48
+ # existing parent of this child, no action is taken. Otherwise, this
49
+ # child is removed from the current parent (if one exists), and is added
50
+ # to the new parent.
51
+ # Returns:: The parent added
52
+ def parent=( other )
53
+ return @parent if @parent == other
54
+ @parent.delete self if defined? @parent and @parent
55
+ @parent = other
56
+ end
57
+
58
+ alias :next_sibling :next_sibling_node
59
+ alias :previous_sibling :previous_sibling_node
60
+
61
+ # Sets the next sibling of this child. This can be used to insert a child
62
+ # after some other child.
63
+ # a = Element.new("a")
64
+ # b = a.add_element("b")
65
+ # c = Element.new("c")
66
+ # b.next_sibling = c
67
+ # # => <a><b/><c/></a>
68
+ def next_sibling=( other )
69
+ parent.insert_after self, other
70
+ end
71
+
72
+ # Sets the previous sibling of this child. This can be used to insert a
73
+ # child before some other child.
74
+ # a = Element.new("a")
75
+ # b = a.add_element("b")
76
+ # c = Element.new("c")
77
+ # b.previous_sibling = c
78
+ # # => <a><b/><c/></a>
79
+ def previous_sibling=(other)
80
+ parent.insert_before self, other
81
+ end
82
+
83
+ # Returns:: the document this child belongs to, or nil if this child
84
+ # belongs to no document
85
+ def document
86
+ return parent.document unless parent.nil?
87
+ nil
88
+ end
89
+
90
+ # This doesn't yet handle encodings
91
+ def bytes
92
+ document.encoding
93
+
94
+ to_s
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: false
2
+ require_relative "child"
3
+
4
+ module REXML
5
+ ##
6
+ # Represents an XML comment; that is, text between \<!-- ... -->
7
+ class Comment < Child
8
+ include Comparable
9
+ START = "<!--"
10
+ STOP = "-->"
11
+
12
+ # The content text
13
+
14
+ attr_accessor :string
15
+
16
+ ##
17
+ # Constructor. The first argument can be one of three types:
18
+ # @param first If String, the contents of this comment are set to the
19
+ # argument. If Comment, the argument is duplicated. If
20
+ # Source, the argument is scanned for a comment.
21
+ # @param second If the first argument is a Source, this argument
22
+ # should be nil, not supplied, or a Parent to be set as the parent
23
+ # of this object
24
+ def initialize( first, second = nil )
25
+ super(second)
26
+ if first.kind_of? String
27
+ @string = first
28
+ elsif first.kind_of? Comment
29
+ @string = first.string
30
+ end
31
+ end
32
+
33
+ def clone
34
+ Comment.new self
35
+ end
36
+
37
+ # == DEPRECATED
38
+ # See REXML::Formatters
39
+ #
40
+ # output::
41
+ # Where to write the string
42
+ # indent::
43
+ # An integer. If -1, no indenting will be used; otherwise, the
44
+ # indentation will be this number of spaces, and children will be
45
+ # indented an additional amount.
46
+ # transitive::
47
+ # Ignored by this class. The contents of comments are never modified.
48
+ # ie_hack::
49
+ # Needed for conformity to the child API, but not used by this class.
50
+ def write( output, indent=-1, transitive=false, ie_hack=false )
51
+ Kernel.warn("Comment.write is deprecated. See REXML::Formatters", uplevel: 1)
52
+ indent( output, indent )
53
+ output << START
54
+ output << @string
55
+ output << STOP
56
+ end
57
+
58
+ alias :to_s :string
59
+
60
+ ##
61
+ # Compares this Comment to another; the contents of the comment are used
62
+ # in the comparison.
63
+ def <=>(other)
64
+ other.to_s <=> @string
65
+ end
66
+
67
+ ##
68
+ # Compares this Comment to another; the contents of the comment are used
69
+ # in the comparison.
70
+ def ==( other )
71
+ other.kind_of? Comment and
72
+ (other <=> self) == 0
73
+ end
74
+
75
+ def node_type
76
+ :comment
77
+ end
78
+ end
79
+ end
80
+ #vim:ts=2 sw=2 noexpandtab: