brakeman 4.10.0 → 5.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +46 -0
- data/README.md +11 -2
- data/bundle/load.rb +5 -3
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/CHANGELOG.md +16 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/FAQ.md +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/Gemfile +1 -4
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/MIT-LICENSE +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/README.md +2 -3
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/REFERENCE.md +29 -7
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/TODO +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/haml.gemspec +2 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_builder.rb +3 -3
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_compiler.rb +42 -31
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/attribute_parser.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/buffer.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/compiler.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/engine.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/error.rb +0 -0
- data/bundle/ruby/2.7.0/gems/haml-5.2.1/lib/haml/escapable.rb +77 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/exec.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/filters.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/generator.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers.rb +7 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_extensions.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_mods.rb +0 -0
- 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
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubi_template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubis_template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/xss_mods.rb +6 -3
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/options.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/parser.rb +32 -4
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/plugin.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/railtie.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/sass_rails_filter.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/template.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/template/options.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/temple_engine.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/temple_line_counter.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/util.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/version.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/yard/default/fulldoc/html/css/common.sass +0 -0
- data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/yard/default/layout/html/footer.erb +0 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.20.1/MIT-LICENSE.txt +20 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel.rb +523 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/processor_count.rb +42 -0
- data/bundle/ruby/2.7.0/gems/parallel-1.20.1/lib/parallel/version.rb +3 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/LICENSE.txt +22 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/NEWS.md +178 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/README.md +48 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml.rb +3 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/attlistdecl.rb +63 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/attribute.rb +205 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/cdata.rb +68 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/child.rb +97 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/comment.rb +80 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/doctype.rb +311 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/document.rb +451 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/attlistdecl.rb +11 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/dtd.rb +47 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/elementdecl.rb +18 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/entitydecl.rb +57 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/dtd/notationdecl.rb +40 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/element.rb +2599 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/encoding.rb +51 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/entity.rb +171 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/default.rb +116 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/pretty.rb +142 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/formatters/transitive.rb +58 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/functions.rb +447 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/instruction.rb +79 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/light/node.rb +188 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/namespace.rb +59 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/node.rb +76 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/output.rb +30 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parent.rb +166 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parseexception.rb +52 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/baseparser.rb +694 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/lightparser.rb +59 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/pullparser.rb +197 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/sax2parser.rb +273 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/streamparser.rb +61 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/treeparser.rb +101 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/ultralightparser.rb +57 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/parsers/xpathparser.rb +689 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/quickpath.rb +266 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/rexml.rb +37 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/sax2listener.rb +98 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/security.rb +28 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/source.rb +298 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/streamlistener.rb +93 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/text.rb +424 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/undefinednamespaceexception.rb +9 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/relaxng.rb +539 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/validation.rb +144 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/validation/validationexception.rb +10 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xmldecl.rb +130 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xmltokens.rb +85 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xpath.rb +81 -0
- data/bundle/ruby/2.7.0/gems/rexml-3.2.5/lib/rexml/xpath_parser.rb +974 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/History.rdoc +25 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/Manifest.txt +2 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/README.rdoc +0 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/compare/normalize.rb +2 -2
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/debugging.md +190 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/rp_extensions.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/rp_stringscanner.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby20_parser.rb +2392 -2384
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby20_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby21_parser.rb +2553 -2550
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby21_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby22_parser.rb +2491 -2471
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby22_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby23_parser.rb +2422 -2403
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby23_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby24_parser.rb +2460 -2450
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby24_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby25_parser.rb +2450 -2441
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby25_parser.y +6 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby26_parser.rb +2444 -2433
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby26_parser.y +7 -1
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby27_parser.rb +7310 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby27_parser.y +21 -1
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.rb +7310 -0
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.16.0/lib/ruby30_parser.y +2677 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rb +19 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rex +1 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_lexer.rex.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser.rb +2 -0
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser.yy +27 -1
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/lib/ruby_parser_extras.rb +2 -2
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/tools/munge.rb +2 -2
- data/bundle/ruby/2.7.0/gems/{ruby_parser-3.15.0 → ruby_parser-3.16.0}/tools/ripper.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/History.rdoc +12 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/Manifest.txt +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/README.rdoc +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/composite_sexp_processor.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/pt_testcase.rb +2 -2
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp_matcher.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/sexp_processor.rb +1 -1
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/strict_sexp.rb +0 -0
- data/bundle/ruby/2.7.0/gems/{sexp_processor-4.15.1 → sexp_processor-4.15.3}/lib/unique.rb +0 -0
- data/lib/brakeman.rb +21 -4
- data/lib/brakeman/app_tree.rb +36 -3
- data/lib/brakeman/checks/base_check.rb +7 -1
- data/lib/brakeman/checks/check_detailed_exceptions.rb +1 -1
- data/lib/brakeman/checks/check_evaluation.rb +1 -1
- data/lib/brakeman/checks/check_execute.rb +2 -1
- data/lib/brakeman/checks/check_mass_assignment.rb +4 -6
- data/lib/brakeman/checks/check_regex_dos.rb +1 -1
- data/lib/brakeman/checks/check_sanitize_methods.rb +2 -1
- data/lib/brakeman/checks/check_sql.rb +16 -3
- data/lib/brakeman/checks/check_unsafe_reflection_methods.rb +68 -0
- data/lib/brakeman/checks/check_verb_confusion.rb +75 -0
- data/lib/brakeman/file_parser.rb +50 -22
- data/lib/brakeman/options.rb +5 -1
- data/lib/brakeman/parsers/template_parser.rb +26 -3
- data/lib/brakeman/processors/alias_processor.rb +91 -19
- data/lib/brakeman/processors/base_processor.rb +4 -4
- data/lib/brakeman/processors/controller_alias_processor.rb +6 -43
- data/lib/brakeman/processors/controller_processor.rb +1 -1
- data/lib/brakeman/processors/haml_template_processor.rb +8 -1
- data/lib/brakeman/processors/lib/call_conversion_helper.rb +10 -0
- data/lib/brakeman/processors/lib/file_type_detector.rb +64 -0
- data/lib/brakeman/processors/lib/rails3_config_processor.rb +16 -16
- data/lib/brakeman/processors/lib/rails4_config_processor.rb +2 -1
- data/lib/brakeman/processors/library_processor.rb +9 -0
- data/lib/brakeman/processors/output_processor.rb +1 -1
- data/lib/brakeman/processors/template_alias_processor.rb +5 -0
- data/lib/brakeman/report.rb +12 -1
- data/lib/brakeman/report/ignore/interactive.rb +1 -1
- data/lib/brakeman/report/report_base.rb +0 -2
- data/lib/brakeman/report/report_csv.rb +37 -60
- data/lib/brakeman/report/report_github.rb +31 -0
- data/lib/brakeman/report/report_junit.rb +2 -2
- data/lib/brakeman/report/report_sarif.rb +1 -1
- data/lib/brakeman/report/report_sonar.rb +38 -0
- data/lib/brakeman/report/report_tabs.rb +1 -1
- data/lib/brakeman/report/report_text.rb +1 -1
- data/lib/brakeman/rescanner.rb +7 -5
- data/lib/brakeman/scanner.rb +47 -18
- data/lib/brakeman/tracker.rb +39 -4
- data/lib/brakeman/tracker/collection.rb +27 -5
- data/lib/brakeman/tracker/config.rb +73 -0
- data/lib/brakeman/tracker/controller.rb +1 -1
- data/lib/brakeman/tracker/method_info.rb +29 -0
- data/lib/brakeman/util.rb +17 -4
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman/warning.rb +10 -2
- data/lib/brakeman/warning_codes.rb +2 -0
- data/lib/ruby_parser/bm_sexp.rb +9 -9
- metadata +149 -84
- data/bundle/ruby/2.7.0/gems/haml-5.1.2/lib/haml/escapable.rb +0 -50
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.15.0/debugging.md +0 -57
- data/bundle/ruby/2.7.0/gems/ruby_parser-3.15.0/lib/ruby27_parser.rb +0 -7224
File without changes
|
File without changes
|
File without changes
|
@@ -607,9 +607,12 @@ MESSAGE
|
|
607
607
|
# @param text [String] The string to sanitize
|
608
608
|
# @return [String] The sanitized string
|
609
609
|
def html_escape(text)
|
610
|
-
|
610
|
+
CGI.escapeHTML(text.to_s)
|
611
611
|
end
|
612
612
|
|
613
|
+
# Always escape text regardless of html_safe?
|
614
|
+
alias_method :html_escape_without_haml_xss, :html_escape
|
615
|
+
|
613
616
|
HTML_ESCAPE_ONCE_REGEX = /['"><]|&(?!(?:[a-zA-Z]+|#(?:\d+|[xX][0-9a-fA-F]+));)/
|
614
617
|
|
615
618
|
# Escapes HTML entities in `text`, but without escaping an ampersand
|
@@ -622,6 +625,9 @@ MESSAGE
|
|
622
625
|
text.gsub(HTML_ESCAPE_ONCE_REGEX, HTML_ESCAPE)
|
623
626
|
end
|
624
627
|
|
628
|
+
# Always escape text once regardless of html_safe?
|
629
|
+
alias_method :escape_once_without_haml_xss, :escape_once
|
630
|
+
|
625
631
|
# Returns whether or not the current template is a Haml template.
|
626
632
|
#
|
627
633
|
# This function, unlike other {Haml::Helpers} functions,
|
data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_extensions.rb
RENAMED
File without changes
|
File without changes
|
data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/action_view_xss_mods.rb
RENAMED
File without changes
|
data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubi_template.rb
RENAMED
File without changes
|
data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/lib/haml/helpers/safe_erubis_template.rb
RENAMED
File without changes
|
@@ -8,12 +8,15 @@ module Haml
|
|
8
8
|
# to work with Rails' XSS protection methods.
|
9
9
|
module XssMods
|
10
10
|
def self.included(base)
|
11
|
-
%w[
|
12
|
-
precede succeed capture_haml haml_concat haml_internal_concat haml_indent
|
13
|
-
escape_once].each do |name|
|
11
|
+
%w[find_and_preserve preserve list_of surround
|
12
|
+
precede succeed capture_haml haml_concat haml_internal_concat haml_indent].each do |name|
|
14
13
|
base.send(:alias_method, "#{name}_without_haml_xss", name)
|
15
14
|
base.send(:alias_method, name, "#{name}_with_haml_xss")
|
16
15
|
end
|
16
|
+
# Those two always have _without_haml_xss
|
17
|
+
%w[html_escape escape_once].each do |name|
|
18
|
+
base.send(:alias_method, name, "#{name}_with_haml_xss")
|
19
|
+
end
|
17
20
|
end
|
18
21
|
|
19
22
|
# Don't escape text that's already safe,
|
File without changes
|
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'ripper'
|
3
4
|
require 'strscan'
|
4
5
|
|
5
6
|
module Haml
|
@@ -90,6 +91,9 @@ module Haml
|
|
90
91
|
ID_KEY = 'id'.freeze
|
91
92
|
CLASS_KEY = 'class'.freeze
|
92
93
|
|
94
|
+
# Used for scanning old attributes, substituting the first '{'
|
95
|
+
METHOD_CALL_PREFIX = 'a('
|
96
|
+
|
93
97
|
def initialize(options)
|
94
98
|
@options = Options.wrap(options)
|
95
99
|
# Record the indent levels of "if" statements to validate the subsequent
|
@@ -307,7 +311,7 @@ module Haml
|
|
307
311
|
return ParseNode.new(:plain, line.index + 1, :text => line.text)
|
308
312
|
end
|
309
313
|
|
310
|
-
escape_html = @options.escape_html if escape_html.nil?
|
314
|
+
escape_html = @options.escape_html && @options.mime_type != 'text/plain' if escape_html.nil?
|
311
315
|
line.text = unescape_interpolation(line.text, escape_html)
|
312
316
|
script(line, false)
|
313
317
|
end
|
@@ -651,13 +655,18 @@ module Haml
|
|
651
655
|
# @return [String] rest
|
652
656
|
# @return [Integer] last_line
|
653
657
|
def parse_old_attributes(text)
|
654
|
-
text = text.dup
|
655
658
|
last_line = @line.index + 1
|
656
659
|
|
657
660
|
begin
|
658
|
-
|
661
|
+
# Old attributes often look like a valid Hash literal, but it sometimes allow code like
|
662
|
+
# `{ hash, foo: bar }`, which is compiled to `_hamlout.attributes({}, nil, hash, foo: bar)`.
|
663
|
+
#
|
664
|
+
# To scan such code correctly, this scans `a( hash, foo: bar }` instead, stops when there is
|
665
|
+
# 1 more :on_embexpr_end (the last '}') than :on_embexpr_beg, and resurrects '{' afterwards.
|
666
|
+
balanced, rest = balance_tokens(text.sub(?{, METHOD_CALL_PREFIX), :on_embexpr_beg, :on_embexpr_end, count: 1)
|
667
|
+
attributes_hash = balanced.sub(METHOD_CALL_PREFIX, ?{)
|
659
668
|
rescue SyntaxError => e
|
660
|
-
if
|
669
|
+
if e.message == Error.message(:unbalanced_brackets) && !@template.empty?
|
661
670
|
text << "\n#{@next_line.text}"
|
662
671
|
last_line += 1
|
663
672
|
next_line
|
@@ -811,6 +820,25 @@ module Haml
|
|
811
820
|
Haml::Util.balance(*args) or raise(SyntaxError.new(Error.message(:unbalanced_brackets)))
|
812
821
|
end
|
813
822
|
|
823
|
+
# Unlike #balance, this balances Ripper tokens to balance something like `{ a: "}" }` correctly.
|
824
|
+
def balance_tokens(buf, start, finish, count: 0)
|
825
|
+
text = ''.dup
|
826
|
+
Ripper.lex(buf).each do |_, token, str|
|
827
|
+
text << str
|
828
|
+
case token
|
829
|
+
when start
|
830
|
+
count += 1
|
831
|
+
when finish
|
832
|
+
count -= 1
|
833
|
+
end
|
834
|
+
|
835
|
+
if count == 0
|
836
|
+
return text, buf.sub(text, '')
|
837
|
+
end
|
838
|
+
end
|
839
|
+
raise SyntaxError.new(Error.message(:unbalanced_brackets))
|
840
|
+
end
|
841
|
+
|
814
842
|
def block_opened?
|
815
843
|
@next_line.tabs > @line.tabs
|
816
844
|
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -213,7 +213,7 @@ MSG
|
|
213
213
|
scan.scan(/\w+/)
|
214
214
|
end
|
215
215
|
content = eval("\"#{interpolated}\"")
|
216
|
-
content
|
216
|
+
content = "#{char}#{content}" if char == '@' || char == '$'
|
217
217
|
content = "Haml::Helpers.html_escape((#{content}))" if escape_html
|
218
218
|
|
219
219
|
res << "\#{#{content}}"
|
data/bundle/ruby/2.7.0/gems/{haml-5.1.2 → haml-5.2.1}/yard/default/fulldoc/html/css/common.sass
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (C) 2013 Michael Grosser <michael@grosser.it>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,523 @@
|
|
1
|
+
require 'rbconfig'
|
2
|
+
require 'parallel/version'
|
3
|
+
require 'parallel/processor_count'
|
4
|
+
|
5
|
+
module Parallel
|
6
|
+
extend ProcessorCount
|
7
|
+
|
8
|
+
Stop = Object.new.freeze
|
9
|
+
|
10
|
+
class DeadWorker < StandardError
|
11
|
+
end
|
12
|
+
|
13
|
+
class Break < StandardError
|
14
|
+
attr_reader :value
|
15
|
+
def initialize(value = nil)
|
16
|
+
@value = value
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Kill < Break
|
21
|
+
end
|
22
|
+
|
23
|
+
class UndumpableException < StandardError
|
24
|
+
attr_reader :backtrace
|
25
|
+
def initialize(original)
|
26
|
+
super "#{original.class}: #{original.message}"
|
27
|
+
@backtrace = original.backtrace
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class ExceptionWrapper
|
32
|
+
attr_reader :exception
|
33
|
+
def initialize(exception)
|
34
|
+
# Remove the bindings stack added by the better_errors gem,
|
35
|
+
# because it cannot be marshalled
|
36
|
+
if exception.instance_variable_defined? :@__better_errors_bindings_stack
|
37
|
+
exception.send :remove_instance_variable, :@__better_errors_bindings_stack
|
38
|
+
end
|
39
|
+
|
40
|
+
@exception =
|
41
|
+
begin
|
42
|
+
Marshal.dump(exception) && exception
|
43
|
+
rescue
|
44
|
+
UndumpableException.new(exception)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Worker
|
50
|
+
attr_reader :pid, :read, :write
|
51
|
+
attr_accessor :thread
|
52
|
+
def initialize(read, write, pid)
|
53
|
+
@read, @write, @pid = read, write, pid
|
54
|
+
end
|
55
|
+
|
56
|
+
def stop
|
57
|
+
close_pipes
|
58
|
+
wait # if it goes zombie, rather wait here to be able to debug
|
59
|
+
end
|
60
|
+
|
61
|
+
# might be passed to started_processes and simultaneously closed by another thread
|
62
|
+
# when running in isolation mode, so we have to check if it is closed before closing
|
63
|
+
def close_pipes
|
64
|
+
read.close unless read.closed?
|
65
|
+
write.close unless write.closed?
|
66
|
+
end
|
67
|
+
|
68
|
+
def work(data)
|
69
|
+
begin
|
70
|
+
Marshal.dump(data, write)
|
71
|
+
rescue Errno::EPIPE
|
72
|
+
raise DeadWorker
|
73
|
+
end
|
74
|
+
|
75
|
+
result = begin
|
76
|
+
Marshal.load(read)
|
77
|
+
rescue EOFError
|
78
|
+
raise DeadWorker
|
79
|
+
end
|
80
|
+
raise result.exception if ExceptionWrapper === result
|
81
|
+
result
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def wait
|
87
|
+
Process.wait(pid)
|
88
|
+
rescue Interrupt
|
89
|
+
# process died
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class JobFactory
|
94
|
+
def initialize(source, mutex)
|
95
|
+
@lambda = (source.respond_to?(:call) && source) || queue_wrapper(source)
|
96
|
+
@source = source.to_a unless @lambda # turn Range and other Enumerable-s into an Array
|
97
|
+
@mutex = mutex
|
98
|
+
@index = -1
|
99
|
+
@stopped = false
|
100
|
+
end
|
101
|
+
|
102
|
+
def next
|
103
|
+
if producer?
|
104
|
+
# - index and item stay in sync
|
105
|
+
# - do not call lambda after it has returned Stop
|
106
|
+
item, index = @mutex.synchronize do
|
107
|
+
return if @stopped
|
108
|
+
item = @lambda.call
|
109
|
+
@stopped = (item == Stop)
|
110
|
+
return if @stopped
|
111
|
+
[item, @index += 1]
|
112
|
+
end
|
113
|
+
else
|
114
|
+
index = @mutex.synchronize { @index += 1 }
|
115
|
+
return if index >= size
|
116
|
+
item = @source[index]
|
117
|
+
end
|
118
|
+
[item, index]
|
119
|
+
end
|
120
|
+
|
121
|
+
def size
|
122
|
+
if producer?
|
123
|
+
Float::INFINITY
|
124
|
+
else
|
125
|
+
@source.size
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# generate item that is sent to workers
|
130
|
+
# just index is faster + less likely to blow up with unserializable errors
|
131
|
+
def pack(item, index)
|
132
|
+
producer? ? [item, index] : index
|
133
|
+
end
|
134
|
+
|
135
|
+
# unpack item that is sent to workers
|
136
|
+
def unpack(data)
|
137
|
+
producer? ? data : [@source[data], data]
|
138
|
+
end
|
139
|
+
|
140
|
+
private
|
141
|
+
|
142
|
+
def producer?
|
143
|
+
@lambda
|
144
|
+
end
|
145
|
+
|
146
|
+
def queue_wrapper(array)
|
147
|
+
array.respond_to?(:num_waiting) && array.respond_to?(:pop) && lambda { array.pop(false) }
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
class UserInterruptHandler
|
152
|
+
INTERRUPT_SIGNAL = :SIGINT
|
153
|
+
|
154
|
+
class << self
|
155
|
+
# kill all these pids or threads if user presses Ctrl+c
|
156
|
+
def kill_on_ctrl_c(pids, options)
|
157
|
+
@to_be_killed ||= []
|
158
|
+
old_interrupt = nil
|
159
|
+
signal = options.fetch(:interrupt_signal, INTERRUPT_SIGNAL)
|
160
|
+
|
161
|
+
if @to_be_killed.empty?
|
162
|
+
old_interrupt = trap_interrupt(signal) do
|
163
|
+
$stderr.puts 'Parallel execution interrupted, exiting ...'
|
164
|
+
@to_be_killed.flatten.each { |pid| kill(pid) }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
@to_be_killed << pids
|
169
|
+
|
170
|
+
yield
|
171
|
+
ensure
|
172
|
+
@to_be_killed.pop # do not kill pids that could be used for new processes
|
173
|
+
restore_interrupt(old_interrupt, signal) if @to_be_killed.empty?
|
174
|
+
end
|
175
|
+
|
176
|
+
def kill(thing)
|
177
|
+
Process.kill(:KILL, thing)
|
178
|
+
rescue Errno::ESRCH
|
179
|
+
# some linux systems already automatically killed the children at this point
|
180
|
+
# so we just ignore them not being there
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
|
185
|
+
def trap_interrupt(signal)
|
186
|
+
old = Signal.trap signal, 'IGNORE'
|
187
|
+
|
188
|
+
Signal.trap signal do
|
189
|
+
yield
|
190
|
+
if !old || old == "DEFAULT"
|
191
|
+
raise Interrupt
|
192
|
+
else
|
193
|
+
old.call
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
old
|
198
|
+
end
|
199
|
+
|
200
|
+
def restore_interrupt(old, signal)
|
201
|
+
Signal.trap signal, old
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
class << self
|
207
|
+
def in_threads(options={:count => 2})
|
208
|
+
threads = []
|
209
|
+
count, _ = extract_count_from_options(options)
|
210
|
+
|
211
|
+
Thread.handle_interrupt(Exception => :never) do
|
212
|
+
begin
|
213
|
+
Thread.handle_interrupt(Exception => :immediate) do
|
214
|
+
count.times do |i|
|
215
|
+
threads << Thread.new { yield(i) }
|
216
|
+
end
|
217
|
+
threads.map(&:value)
|
218
|
+
end
|
219
|
+
ensure
|
220
|
+
threads.each(&:kill)
|
221
|
+
end
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
def in_processes(options = {}, &block)
|
226
|
+
count, options = extract_count_from_options(options)
|
227
|
+
count ||= processor_count
|
228
|
+
map(0...count, options.merge(:in_processes => count), &block)
|
229
|
+
end
|
230
|
+
|
231
|
+
def each(array, options={}, &block)
|
232
|
+
map(array, options.merge(:preserve_results => false), &block)
|
233
|
+
end
|
234
|
+
|
235
|
+
def any?(*args, &block)
|
236
|
+
raise "You must provide a block when calling #any?" if block.nil?
|
237
|
+
!each(*args) { |*a| raise Kill if block.call(*a) }
|
238
|
+
end
|
239
|
+
|
240
|
+
def all?(*args, &block)
|
241
|
+
raise "You must provide a block when calling #all?" if block.nil?
|
242
|
+
!!each(*args) { |*a| raise Kill unless block.call(*a) }
|
243
|
+
end
|
244
|
+
|
245
|
+
def each_with_index(array, options={}, &block)
|
246
|
+
each(array, options.merge(:with_index => true), &block)
|
247
|
+
end
|
248
|
+
|
249
|
+
def map(source, options = {}, &block)
|
250
|
+
options = options.dup
|
251
|
+
options[:mutex] = Mutex.new
|
252
|
+
|
253
|
+
if options[:in_processes] && options[:in_threads]
|
254
|
+
raise ArgumentError.new("Please specify only one of `in_processes` or `in_threads`.")
|
255
|
+
elsif RUBY_PLATFORM =~ /java/ and not options[:in_processes]
|
256
|
+
method = :in_threads
|
257
|
+
size = options[method] || processor_count
|
258
|
+
elsif options[:in_threads]
|
259
|
+
method = :in_threads
|
260
|
+
size = options[method]
|
261
|
+
else
|
262
|
+
method = :in_processes
|
263
|
+
if Process.respond_to?(:fork)
|
264
|
+
size = options[method] || processor_count
|
265
|
+
else
|
266
|
+
warn "Process.fork is not supported by this Ruby"
|
267
|
+
size = 0
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
job_factory = JobFactory.new(source, options[:mutex])
|
272
|
+
size = [job_factory.size, size].min
|
273
|
+
|
274
|
+
options[:return_results] = (options[:preserve_results] != false || !!options[:finish])
|
275
|
+
add_progress_bar!(job_factory, options)
|
276
|
+
|
277
|
+
result =
|
278
|
+
if size == 0
|
279
|
+
work_direct(job_factory, options, &block)
|
280
|
+
elsif method == :in_threads
|
281
|
+
work_in_threads(job_factory, options.merge(:count => size), &block)
|
282
|
+
else
|
283
|
+
work_in_processes(job_factory, options.merge(:count => size), &block)
|
284
|
+
end
|
285
|
+
|
286
|
+
return result.value if result.is_a?(Break)
|
287
|
+
raise result if result.is_a?(Exception)
|
288
|
+
options[:return_results] ? result : source
|
289
|
+
end
|
290
|
+
|
291
|
+
def map_with_index(array, options={}, &block)
|
292
|
+
map(array, options.merge(:with_index => true), &block)
|
293
|
+
end
|
294
|
+
|
295
|
+
def flat_map(*args, &block)
|
296
|
+
map(*args, &block).flatten(1)
|
297
|
+
end
|
298
|
+
|
299
|
+
def worker_number
|
300
|
+
Thread.current[:parallel_worker_number]
|
301
|
+
end
|
302
|
+
|
303
|
+
# TODO: this does not work when doing threads in forks, so should remove and yield the number instead if needed
|
304
|
+
def worker_number=(worker_num)
|
305
|
+
Thread.current[:parallel_worker_number] = worker_num
|
306
|
+
end
|
307
|
+
|
308
|
+
private
|
309
|
+
|
310
|
+
def add_progress_bar!(job_factory, options)
|
311
|
+
if progress_options = options[:progress]
|
312
|
+
raise "Progressbar can only be used with array like items" if job_factory.size == Float::INFINITY
|
313
|
+
require 'ruby-progressbar'
|
314
|
+
|
315
|
+
if progress_options == true
|
316
|
+
progress_options = { title: "Progress" }
|
317
|
+
elsif progress_options.respond_to? :to_str
|
318
|
+
progress_options = { title: progress_options.to_str }
|
319
|
+
end
|
320
|
+
|
321
|
+
progress_options = {
|
322
|
+
total: job_factory.size,
|
323
|
+
format: '%t |%E | %B | %a'
|
324
|
+
}.merge(progress_options)
|
325
|
+
|
326
|
+
progress = ProgressBar.create(progress_options)
|
327
|
+
old_finish = options[:finish]
|
328
|
+
options[:finish] = lambda do |item, i, result|
|
329
|
+
old_finish.call(item, i, result) if old_finish
|
330
|
+
progress.increment
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
def work_direct(job_factory, options, &block)
|
336
|
+
self.worker_number = 0
|
337
|
+
results = []
|
338
|
+
exception = nil
|
339
|
+
begin
|
340
|
+
while set = job_factory.next
|
341
|
+
item, index = set
|
342
|
+
results << with_instrumentation(item, index, options) do
|
343
|
+
call_with_index(item, index, options, &block)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
rescue
|
347
|
+
exception = $!
|
348
|
+
end
|
349
|
+
exception || results
|
350
|
+
ensure
|
351
|
+
self.worker_number = nil
|
352
|
+
end
|
353
|
+
|
354
|
+
def work_in_threads(job_factory, options, &block)
|
355
|
+
raise "interrupt_signal is no longer supported for threads" if options[:interrupt_signal]
|
356
|
+
results = []
|
357
|
+
results_mutex = Mutex.new # arrays are not thread-safe on jRuby
|
358
|
+
exception = nil
|
359
|
+
|
360
|
+
in_threads(options) do |worker_num|
|
361
|
+
self.worker_number = worker_num
|
362
|
+
# as long as there are more jobs, work on one of them
|
363
|
+
while !exception && set = job_factory.next
|
364
|
+
begin
|
365
|
+
item, index = set
|
366
|
+
result = with_instrumentation item, index, options do
|
367
|
+
call_with_index(item, index, options, &block)
|
368
|
+
end
|
369
|
+
results_mutex.synchronize { results[index] = result }
|
370
|
+
rescue
|
371
|
+
exception = $!
|
372
|
+
end
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
exception || results
|
377
|
+
end
|
378
|
+
|
379
|
+
def work_in_processes(job_factory, options, &blk)
|
380
|
+
workers = create_workers(job_factory, options, &blk)
|
381
|
+
results = []
|
382
|
+
results_mutex = Mutex.new # arrays are not thread-safe
|
383
|
+
exception = nil
|
384
|
+
|
385
|
+
UserInterruptHandler.kill_on_ctrl_c(workers.map(&:pid), options) do
|
386
|
+
in_threads(options) do |i|
|
387
|
+
worker = workers[i]
|
388
|
+
worker.thread = Thread.current
|
389
|
+
worked = false
|
390
|
+
|
391
|
+
begin
|
392
|
+
loop do
|
393
|
+
break if exception
|
394
|
+
item, index = job_factory.next
|
395
|
+
break unless index
|
396
|
+
|
397
|
+
if options[:isolation]
|
398
|
+
worker = replace_worker(job_factory, workers, i, options, blk) if worked
|
399
|
+
worked = true
|
400
|
+
worker.thread = Thread.current
|
401
|
+
end
|
402
|
+
|
403
|
+
begin
|
404
|
+
result = with_instrumentation item, index, options do
|
405
|
+
worker.work(job_factory.pack(item, index))
|
406
|
+
end
|
407
|
+
results_mutex.synchronize { results[index] = result } # arrays are not threads safe on jRuby
|
408
|
+
rescue StandardError => e
|
409
|
+
exception = e
|
410
|
+
if Kill === exception
|
411
|
+
(workers - [worker]).each do |w|
|
412
|
+
w.thread.kill if w.thread
|
413
|
+
UserInterruptHandler.kill(w.pid)
|
414
|
+
end
|
415
|
+
end
|
416
|
+
end
|
417
|
+
end
|
418
|
+
ensure
|
419
|
+
worker.stop
|
420
|
+
end
|
421
|
+
end
|
422
|
+
end
|
423
|
+
exception || results
|
424
|
+
end
|
425
|
+
|
426
|
+
def replace_worker(job_factory, workers, i, options, blk)
|
427
|
+
options[:mutex].synchronize do
|
428
|
+
# old worker is no longer used ... stop it
|
429
|
+
worker = workers[i]
|
430
|
+
worker.stop
|
431
|
+
|
432
|
+
# create a new replacement worker
|
433
|
+
running = workers - [worker]
|
434
|
+
workers[i] = worker(job_factory, options.merge(started_workers: running, worker_number: i), &blk)
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
def create_workers(job_factory, options, &block)
|
439
|
+
workers = []
|
440
|
+
Array.new(options[:count]).each_with_index do |_, i|
|
441
|
+
workers << worker(job_factory, options.merge(started_workers: workers, worker_number: i), &block)
|
442
|
+
end
|
443
|
+
workers
|
444
|
+
end
|
445
|
+
|
446
|
+
def worker(job_factory, options, &block)
|
447
|
+
child_read, parent_write = IO.pipe
|
448
|
+
parent_read, child_write = IO.pipe
|
449
|
+
|
450
|
+
pid = Process.fork do
|
451
|
+
self.worker_number = options[:worker_number]
|
452
|
+
|
453
|
+
begin
|
454
|
+
options.delete(:started_workers).each(&:close_pipes)
|
455
|
+
|
456
|
+
parent_write.close
|
457
|
+
parent_read.close
|
458
|
+
|
459
|
+
process_incoming_jobs(child_read, child_write, job_factory, options, &block)
|
460
|
+
ensure
|
461
|
+
child_read.close
|
462
|
+
child_write.close
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
child_read.close
|
467
|
+
child_write.close
|
468
|
+
|
469
|
+
Worker.new(parent_read, parent_write, pid)
|
470
|
+
end
|
471
|
+
|
472
|
+
def process_incoming_jobs(read, write, job_factory, options, &block)
|
473
|
+
until read.eof?
|
474
|
+
data = Marshal.load(read)
|
475
|
+
item, index = job_factory.unpack(data)
|
476
|
+
result = begin
|
477
|
+
call_with_index(item, index, options, &block)
|
478
|
+
# https://github.com/rspec/rspec-support/blob/673133cdd13b17077b3d88ece8d7380821f8d7dc/lib/rspec/support.rb#L132-L140
|
479
|
+
rescue NoMemoryError, SignalException, Interrupt, SystemExit
|
480
|
+
raise $!
|
481
|
+
rescue Exception
|
482
|
+
ExceptionWrapper.new($!)
|
483
|
+
end
|
484
|
+
begin
|
485
|
+
Marshal.dump(result, write)
|
486
|
+
rescue Errno::EPIPE
|
487
|
+
return # parent thread already dead
|
488
|
+
end
|
489
|
+
end
|
490
|
+
end
|
491
|
+
|
492
|
+
# options is either a Integer or a Hash with :count
|
493
|
+
def extract_count_from_options(options)
|
494
|
+
if options.is_a?(Hash)
|
495
|
+
count = options[:count]
|
496
|
+
else
|
497
|
+
count = options
|
498
|
+
options = {}
|
499
|
+
end
|
500
|
+
[count, options]
|
501
|
+
end
|
502
|
+
|
503
|
+
def call_with_index(item, index, options, &block)
|
504
|
+
args = [item]
|
505
|
+
args << index if options[:with_index]
|
506
|
+
if options[:return_results]
|
507
|
+
block.call(*args)
|
508
|
+
else
|
509
|
+
block.call(*args)
|
510
|
+
nil # avoid GC overhead of passing large results around
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
def with_instrumentation(item, index, options)
|
515
|
+
on_start = options[:start]
|
516
|
+
on_finish = options[:finish]
|
517
|
+
options[:mutex].synchronize { on_start.call(item, index) } if on_start
|
518
|
+
result = yield
|
519
|
+
options[:mutex].synchronize { on_finish.call(item, index, result) } if on_finish
|
520
|
+
result unless options[:preserve_results] == false
|
521
|
+
end
|
522
|
+
end
|
523
|
+
end
|