brakeman 4.10.0 → 5.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGES.md +46 -0
  3. data/README.md +11 -2
  4. data/bundle/load.rb +5 -3
  5. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/CHANGELOG.md +16 -0
  6. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/FAQ.md +0 -0
  7. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/Gemfile +1 -4
  8. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/MIT-LICENSE +0 -0
  9. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/README.md +2 -3
  10. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/REFERENCE.md +29 -7
  11. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/TODO +0 -0
  12. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/haml.gemspec +2 -1
  13. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml.rb +0 -0
  14. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_builder.rb +3 -3
  15. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_compiler.rb +42 -31
  16. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_parser.rb +0 -0
  17. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/buffer.rb +0 -0
  18. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/compiler.rb +0 -0
  19. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/engine.rb +0 -0
  20. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/error.rb +0 -0
  21. data/bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/escapable.rb +77 -0
  22. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/exec.rb +0 -0
  23. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/filters.rb +0 -0
  24. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/generator.rb +0 -0
  25. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers.rb +7 -1
  26. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_extensions.rb +0 -0
  27. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_mods.rb +0 -0
  28. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_xss_mods.rb +0 -0
  29. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubi_template.rb +0 -0
  30. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubis_template.rb +0 -0
  31. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/xss_mods.rb +6 -3
  32. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/options.rb +0 -0
  33. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/parser.rb +32 -4
  34. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/plugin.rb +0 -0
  35. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/railtie.rb +0 -0
  36. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/sass_rails_filter.rb +0 -0
  37. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/template.rb +0 -0
  38. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/template/options.rb +0 -0
  39. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/temple_engine.rb +0 -0
  40. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/temple_line_counter.rb +0 -0
  41. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/util.rb +1 -1
  42. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/version.rb +1 -1
  43. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/yard/default/fulldoc/html/css/common.sass +0 -0
  44. data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/yard/default/layout/html/footer.erb +0 -0
  45. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/MIT-LICENSE.txt +20 -0
  46. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel.rb +523 -0
  47. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb +42 -0
  48. data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb +3 -0
  49. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/LICENSE.txt +22 -0
  50. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/NEWS.md +178 -0
  51. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/README.md +48 -0
  52. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml.rb +3 -0
  53. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb +63 -0
  54. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/attribute.rb +205 -0
  55. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/cdata.rb +68 -0
  56. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/child.rb +97 -0
  57. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/comment.rb +80 -0
  58. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/doctype.rb +311 -0
  59. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/document.rb +451 -0
  60. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/attlistdecl.rb +11 -0
  61. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/dtd.rb +47 -0
  62. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/elementdecl.rb +18 -0
  63. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/entitydecl.rb +57 -0
  64. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/notationdecl.rb +40 -0
  65. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/element.rb +2599 -0
  66. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/encoding.rb +51 -0
  67. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/entity.rb +171 -0
  68. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb +116 -0
  69. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/pretty.rb +142 -0
  70. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/transitive.rb +58 -0
  71. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/functions.rb +447 -0
  72. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/instruction.rb +79 -0
  73. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/light/node.rb +188 -0
  74. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/namespace.rb +59 -0
  75. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/node.rb +76 -0
  76. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/output.rb +30 -0
  77. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parent.rb +166 -0
  78. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parseexception.rb +52 -0
  79. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb +694 -0
  80. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/lightparser.rb +59 -0
  81. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb +197 -0
  82. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb +273 -0
  83. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb +61 -0
  84. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/treeparser.rb +101 -0
  85. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/ultralightparser.rb +57 -0
  86. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/xpathparser.rb +689 -0
  87. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/quickpath.rb +266 -0
  88. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/rexml.rb +37 -0
  89. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/sax2listener.rb +98 -0
  90. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/security.rb +28 -0
  91. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/source.rb +298 -0
  92. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/streamlistener.rb +93 -0
  93. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/text.rb +424 -0
  94. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/undefinednamespaceexception.rb +9 -0
  95. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/relaxng.rb +539 -0
  96. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/validation.rb +144 -0
  97. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/validationexception.rb +10 -0
  98. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xmldecl.rb +130 -0
  99. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xmltokens.rb +85 -0
  100. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xpath.rb +81 -0
  101. data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb +974 -0
  102. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/History.rdoc +25 -0
  103. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/Manifest.txt +2 -0
  104. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/README.rdoc +0 -0
  105. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/compare/normalize.rb +2 -2
  106. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/debugging.md +190 -0
  107. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/rp_extensions.rb +0 -0
  108. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/rp_stringscanner.rb +0 -0
  109. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby20_parser.rb +2392 -2384
  110. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby20_parser.y +6 -1
  111. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby21_parser.rb +2553 -2550
  112. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby21_parser.y +6 -1
  113. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby22_parser.rb +2491 -2471
  114. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby22_parser.y +6 -1
  115. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby23_parser.rb +2422 -2403
  116. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby23_parser.y +6 -1
  117. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby24_parser.rb +2460 -2450
  118. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby24_parser.y +6 -1
  119. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby25_parser.rb +2450 -2441
  120. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby25_parser.y +6 -1
  121. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby26_parser.rb +2444 -2433
  122. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby26_parser.y +7 -1
  123. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +7310 -0
  124. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby27_parser.y +21 -1
  125. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +7310 -0
  126. data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.y +2677 -0
  127. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rb +19 -0
  128. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rex +1 -1
  129. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rex.rb +1 -1
  130. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser.rb +2 -0
  131. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser.yy +27 -1
  132. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser_extras.rb +2 -2
  133. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/tools/munge.rb +2 -2
  134. data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/tools/ripper.rb +0 -0
  135. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/History.rdoc +12 -0
  136. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/Manifest.txt +0 -0
  137. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/README.rdoc +0 -0
  138. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/composite_sexp_processor.rb +0 -0
  139. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/pt_testcase.rb +2 -2
  140. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp.rb +0 -0
  141. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp_matcher.rb +0 -0
  142. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp_processor.rb +1 -1
  143. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/strict_sexp.rb +0 -0
  144. data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/unique.rb +0 -0
  145. data/lib/brakeman.rb +21 -4
  146. data/lib/brakeman/app_tree.rb +36 -3
  147. data/lib/brakeman/checks/base_check.rb +7 -1
  148. data/lib/brakeman/checks/check_detailed_exceptions.rb +1 -1
  149. data/lib/brakeman/checks/check_evaluation.rb +1 -1
  150. data/lib/brakeman/checks/check_execute.rb +2 -1
  151. data/lib/brakeman/checks/check_mass_assignment.rb +4 -6
  152. data/lib/brakeman/checks/check_regex_dos.rb +1 -1
  153. data/lib/brakeman/checks/check_sanitize_methods.rb +2 -1
  154. data/lib/brakeman/checks/check_sql.rb +16 -3
  155. data/lib/brakeman/checks/check_unsafe_reflection_methods.rb +68 -0
  156. data/lib/brakeman/checks/check_verb_confusion.rb +75 -0
  157. data/lib/brakeman/file_parser.rb +50 -22
  158. data/lib/brakeman/options.rb +5 -1
  159. data/lib/brakeman/parsers/template_parser.rb +26 -3
  160. data/lib/brakeman/processors/alias_processor.rb +91 -19
  161. data/lib/brakeman/processors/base_processor.rb +4 -4
  162. data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
  163. data/lib/brakeman/processors/controller_processor.rb +1 -1
  164. data/lib/brakeman/processors/haml_template_processor.rb +8 -1
  165. data/lib/brakeman/processors/lib/call_conversion_helper.rb +10 -0
  166. data/lib/brakeman/processors/lib/file_type_detector.rb +64 -0
  167. data/lib/brakeman/processors/lib/rails3_config_processor.rb +16 -16
  168. data/lib/brakeman/processors/lib/rails4_config_processor.rb +2 -1
  169. data/lib/brakeman/processors/library_processor.rb +9 -0
  170. data/lib/brakeman/processors/output_processor.rb +1 -1
  171. data/lib/brakeman/processors/template_alias_processor.rb +5 -0
  172. data/lib/brakeman/report.rb +12 -1
  173. data/lib/brakeman/report/ignore/interactive.rb +1 -1
  174. data/lib/brakeman/report/report_base.rb +0 -2
  175. data/lib/brakeman/report/report_csv.rb +37 -60
  176. data/lib/brakeman/report/report_github.rb +31 -0
  177. data/lib/brakeman/report/report_junit.rb +2 -2
  178. data/lib/brakeman/report/report_sarif.rb +1 -1
  179. data/lib/brakeman/report/report_sonar.rb +38 -0
  180. data/lib/brakeman/report/report_tabs.rb +1 -1
  181. data/lib/brakeman/report/report_text.rb +1 -1
  182. data/lib/brakeman/rescanner.rb +7 -5
  183. data/lib/brakeman/scanner.rb +47 -18
  184. data/lib/brakeman/tracker.rb +39 -4
  185. data/lib/brakeman/tracker/collection.rb +27 -5
  186. data/lib/brakeman/tracker/config.rb +73 -0
  187. data/lib/brakeman/tracker/controller.rb +1 -1
  188. data/lib/brakeman/tracker/method_info.rb +29 -0
  189. data/lib/brakeman/util.rb +17 -4
  190. data/lib/brakeman/version.rb +1 -1
  191. data/lib/brakeman/warning.rb +10 -2
  192. data/lib/brakeman/warning_codes.rb +2 -0
  193. data/lib/ruby_parser/bm_sexp.rb +9 -9
  194. metadata +149 -84
  195. data/bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb +0 -50
  196. data/bundle/ruby/2.7.0/gems/ruby_parser-3.15.0/debugging.md +0 -57
  197. data/bundle/ruby/2.7.0/gems/ruby_parser-3.15.0/lib/ruby27_parser.rb +0 -7224
@@ -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:
@@ -0,0 +1,311 @@
1
+ # frozen_string_literal: false
2
+ require_relative "parent"
3
+ require_relative "parseexception"
4
+ require_relative "namespace"
5
+ require_relative 'entity'
6
+ require_relative 'attlistdecl'
7
+ require_relative 'xmltokens'
8
+
9
+ module REXML
10
+ class ReferenceWriter
11
+ def initialize(id_type,
12
+ public_id_literal,
13
+ system_literal,
14
+ context=nil)
15
+ @id_type = id_type
16
+ @public_id_literal = public_id_literal
17
+ @system_literal = system_literal
18
+ if context and context[:prologue_quote] == :apostrophe
19
+ @default_quote = "'"
20
+ else
21
+ @default_quote = "\""
22
+ end
23
+ end
24
+
25
+ def write(output)
26
+ output << " #{@id_type}"
27
+ if @public_id_literal
28
+ if @public_id_literal.include?("'")
29
+ quote = "\""
30
+ else
31
+ quote = @default_quote
32
+ end
33
+ output << " #{quote}#{@public_id_literal}#{quote}"
34
+ end
35
+ if @system_literal
36
+ if @system_literal.include?("'")
37
+ quote = "\""
38
+ elsif @system_literal.include?("\"")
39
+ quote = "'"
40
+ else
41
+ quote = @default_quote
42
+ end
43
+ output << " #{quote}#{@system_literal}#{quote}"
44
+ end
45
+ end
46
+ end
47
+
48
+ # Represents an XML DOCTYPE declaration; that is, the contents of <!DOCTYPE
49
+ # ... >. DOCTYPES can be used to declare the DTD of a document, as well as
50
+ # being used to declare entities used in the document.
51
+ class DocType < Parent
52
+ include XMLTokens
53
+ START = "<!DOCTYPE"
54
+ STOP = ">"
55
+ SYSTEM = "SYSTEM"
56
+ PUBLIC = "PUBLIC"
57
+ DEFAULT_ENTITIES = {
58
+ 'gt'=>EntityConst::GT,
59
+ 'lt'=>EntityConst::LT,
60
+ 'quot'=>EntityConst::QUOT,
61
+ "apos"=>EntityConst::APOS
62
+ }
63
+
64
+ # name is the name of the doctype
65
+ # external_id is the referenced DTD, if given
66
+ attr_reader :name, :external_id, :entities, :namespaces
67
+
68
+ # Constructor
69
+ #
70
+ # dt = DocType.new( 'foo', '-//I/Hate/External/IDs' )
71
+ # # <!DOCTYPE foo '-//I/Hate/External/IDs'>
72
+ # dt = DocType.new( doctype_to_clone )
73
+ # # Incomplete. Shallow clone of doctype
74
+ #
75
+ # +Note+ that the constructor:
76
+ #
77
+ # Doctype.new( Source.new( "<!DOCTYPE foo 'bar'>" ) )
78
+ #
79
+ # is _deprecated_. Do not use it. It will probably disappear.
80
+ def initialize( first, parent=nil )
81
+ @entities = DEFAULT_ENTITIES
82
+ @long_name = @uri = nil
83
+ if first.kind_of? String
84
+ super()
85
+ @name = first
86
+ @external_id = parent
87
+ elsif first.kind_of? DocType
88
+ super( parent )
89
+ @name = first.name
90
+ @external_id = first.external_id
91
+ @long_name = first.instance_variable_get(:@long_name)
92
+ @uri = first.instance_variable_get(:@uri)
93
+ elsif first.kind_of? Array
94
+ super( parent )
95
+ @name = first[0]
96
+ @external_id = first[1]
97
+ @long_name = first[2]
98
+ @uri = first[3]
99
+ elsif first.kind_of? Source
100
+ super( parent )
101
+ parser = Parsers::BaseParser.new( first )
102
+ event = parser.pull
103
+ if event[0] == :start_doctype
104
+ @name, @external_id, @long_name, @uri, = event[1..-1]
105
+ end
106
+ else
107
+ super()
108
+ end
109
+ end
110
+
111
+ def node_type
112
+ :doctype
113
+ end
114
+
115
+ def attributes_of element
116
+ rv = []
117
+ each do |child|
118
+ child.each do |key,val|
119
+ rv << Attribute.new(key,val)
120
+ end if child.kind_of? AttlistDecl and child.element_name == element
121
+ end
122
+ rv
123
+ end
124
+
125
+ def attribute_of element, attribute
126
+ att_decl = find do |child|
127
+ child.kind_of? AttlistDecl and
128
+ child.element_name == element and
129
+ child.include? attribute
130
+ end
131
+ return nil unless att_decl
132
+ att_decl[attribute]
133
+ end
134
+
135
+ def clone
136
+ DocType.new self
137
+ end
138
+
139
+ # output::
140
+ # Where to write the string
141
+ # indent::
142
+ # An integer. If -1, no indentation will be used; otherwise, the
143
+ # indentation will be this number of spaces, and children will be
144
+ # indented an additional amount.
145
+ # transitive::
146
+ # Ignored
147
+ # ie_hack::
148
+ # Ignored
149
+ def write( output, indent=0, transitive=false, ie_hack=false )
150
+ f = REXML::Formatters::Default.new
151
+ indent( output, indent )
152
+ output << START
153
+ output << ' '
154
+ output << @name
155
+ if @external_id
156
+ reference_writer = ReferenceWriter.new(@external_id,
157
+ @long_name,
158
+ @uri,
159
+ context)
160
+ reference_writer.write(output)
161
+ end
162
+ unless @children.empty?
163
+ output << ' ['
164
+ @children.each { |child|
165
+ output << "\n"
166
+ f.write( child, output )
167
+ }
168
+ output << "\n]"
169
+ end
170
+ output << STOP
171
+ end
172
+
173
+ def context
174
+ if @parent
175
+ @parent.context
176
+ else
177
+ nil
178
+ end
179
+ end
180
+
181
+ def entity( name )
182
+ @entities[name].unnormalized if @entities[name]
183
+ end
184
+
185
+ def add child
186
+ super(child)
187
+ @entities = DEFAULT_ENTITIES.clone if @entities == DEFAULT_ENTITIES
188
+ @entities[ child.name ] = child if child.kind_of? Entity
189
+ end
190
+
191
+ # This method retrieves the public identifier identifying the document's
192
+ # DTD.
193
+ #
194
+ # Method contributed by Henrik Martensson
195
+ def public
196
+ case @external_id
197
+ when "SYSTEM"
198
+ nil
199
+ when "PUBLIC"
200
+ @long_name
201
+ end
202
+ end
203
+
204
+ # This method retrieves the system identifier identifying the document's DTD
205
+ #
206
+ # Method contributed by Henrik Martensson
207
+ def system
208
+ case @external_id
209
+ when "SYSTEM"
210
+ @long_name
211
+ when "PUBLIC"
212
+ @uri.kind_of?(String) ? @uri : nil
213
+ end
214
+ end
215
+
216
+ # This method returns a list of notations that have been declared in the
217
+ # _internal_ DTD subset. Notations in the external DTD subset are not
218
+ # listed.
219
+ #
220
+ # Method contributed by Henrik Martensson
221
+ def notations
222
+ children().select {|node| node.kind_of?(REXML::NotationDecl)}
223
+ end
224
+
225
+ # Retrieves a named notation. Only notations declared in the internal
226
+ # DTD subset can be retrieved.
227
+ #
228
+ # Method contributed by Henrik Martensson
229
+ def notation(name)
230
+ notations.find { |notation_decl|
231
+ notation_decl.name == name
232
+ }
233
+ end
234
+ end
235
+
236
+ # We don't really handle any of these since we're not a validating
237
+ # parser, so we can be pretty dumb about them. All we need to be able
238
+ # to do is spew them back out on a write()
239
+
240
+ # This is an abstract class. You never use this directly; it serves as a
241
+ # parent class for the specific declarations.
242
+ class Declaration < Child
243
+ def initialize src
244
+ super()
245
+ @string = src
246
+ end
247
+
248
+ def to_s
249
+ @string+'>'
250
+ end
251
+
252
+ # == DEPRECATED
253
+ # See REXML::Formatters
254
+ #
255
+ def write( output, indent )
256
+ output << to_s
257
+ end
258
+ end
259
+
260
+ public
261
+ class ElementDecl < Declaration
262
+ def initialize( src )
263
+ super
264
+ end
265
+ end
266
+
267
+ class ExternalEntity < Child
268
+ def initialize( src )
269
+ super()
270
+ @entity = src
271
+ end
272
+ def to_s
273
+ @entity
274
+ end
275
+ def write( output, indent )
276
+ output << @entity
277
+ end
278
+ end
279
+
280
+ class NotationDecl < Child
281
+ attr_accessor :public, :system
282
+ def initialize name, middle, pub, sys
283
+ super(nil)
284
+ @name = name
285
+ @middle = middle
286
+ @public = pub
287
+ @system = sys
288
+ end
289
+
290
+ def to_s
291
+ context = nil
292
+ context = parent.context if parent
293
+ notation = "<!NOTATION #{@name}"
294
+ reference_writer = ReferenceWriter.new(@middle, @public, @system, context)
295
+ reference_writer.write(notation)
296
+ notation << ">"
297
+ notation
298
+ end
299
+
300
+ def write( output, indent=-1 )
301
+ output << to_s
302
+ end
303
+
304
+ # This method retrieves the name of the notation.
305
+ #
306
+ # Method contributed by Henrik Martensson
307
+ def name
308
+ @name
309
+ end
310
+ end
311
+ end