brakeman 7.1.2 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGES.md +11 -0
- data/README.md +1 -1
- data/bundle/load.rb +2 -2
- data/bundle/ruby/3.2.0/gems/erubi-1.13.1/CHANGELOG +111 -0
- data/bundle/ruby/3.2.0/gems/{erubis-2.7.0 → erubi-1.13.1}/MIT-LICENSE +1 -0
- data/bundle/ruby/3.2.0/gems/erubi-1.13.1/README.rdoc +151 -0
- data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_block.rb +91 -0
- data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi/capture_end.rb +58 -0
- data/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib/erubi.rb +299 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/asciidoc.rb +12 -5
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/babel.rb +5 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/builder.rb +4 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/coffee.rb +14 -4
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/commonmarker.rb +41 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/csv.rb +63 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/erb.rb +130 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/erubi.rb +41 -8
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/etanni.rb +7 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/haml.rb +67 -1
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/kramdown.rb +59 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/liquid.rb +93 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/livescript.rb +11 -4
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/mapping.rb +8 -8
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/markaby.rb +11 -2
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/nokogiri.rb +13 -2
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/pandoc.rb +81 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/pipeline.rb +6 -1
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/plain.rb +5 -1
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/prawn.rb +17 -6
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/radius.rb +96 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdiscount.rb +82 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rdoc.rb +33 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcarpet.rb +73 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/redcloth.rb +40 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/rst-pandoc.rb +33 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/sass.rb +16 -3
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/slim.rb +18 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/string.rb +10 -2
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/template.rb +5 -5
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/typescript.rb +5 -0
- data/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib/tilt/yajl.rb +91 -0
- data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt.rb +1 -2
- data/lib/brakeman/app_tree.rb +7 -2
- data/lib/brakeman/checks/check_model_attributes.rb +1 -1
- data/lib/brakeman/checks/check_render.rb +1 -27
- data/lib/brakeman/checks/check_render_rce.rb +43 -0
- data/lib/brakeman/checks/check_session_settings.rb +1 -1
- data/lib/brakeman/checks.rb +31 -25
- data/lib/brakeman/commandline.rb +6 -1
- data/lib/brakeman/file_parser.rb +3 -2
- data/lib/brakeman/logger.rb +264 -0
- data/lib/brakeman/options.rb +0 -9
- data/lib/brakeman/parsers/rails_erubi.rb +82 -0
- data/lib/brakeman/parsers/template_parser.rb +7 -15
- data/lib/brakeman/processor.rb +2 -2
- data/lib/brakeman/processors/controller_alias_processor.rb +1 -1
- data/lib/brakeman/processors/controller_processor.rb +3 -3
- data/lib/brakeman/processors/{erubis_template_processor.rb → erubi_template_procesor.rb} +3 -3
- data/lib/brakeman/processors/lib/rails2_config_processor.rb +4 -3
- data/lib/brakeman/processors/lib/rails2_route_processor.rb +1 -1
- data/lib/brakeman/processors/lib/render_helper.rb +1 -1
- data/lib/brakeman/processors/lib/render_path.rb +1 -1
- data/lib/brakeman/processors/model_processor.rb +1 -1
- data/lib/brakeman/report/ignore/config.rb +1 -1
- data/lib/brakeman/scanner.rb +25 -49
- data/lib/brakeman/tracker/collection.rb +12 -2
- data/lib/brakeman/tracker/config.rb +17 -13
- data/lib/brakeman/tracker/constants.rb +17 -2
- data/lib/brakeman/tracker/controller.rb +1 -1
- data/lib/brakeman/tracker.rb +7 -15
- data/lib/brakeman/version.rb +1 -1
- data/lib/brakeman.rb +89 -49
- metadata +51 -80
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/CHANGES.txt +0 -828
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/README.txt +0 -102
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis +0 -3468
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/erubis-run.rb +0 -132
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/contrib/inline-require +0 -179
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/context.rb +0 -83
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/converter.rb +0 -357
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ec.rb +0 -117
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ecpp.rb +0 -113
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejava.rb +0 -110
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ejavascript.rb +0 -119
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/enhanced.rb +0 -126
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eperl.rb +0 -95
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/ephp.rb +0 -99
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/eruby.rb +0 -125
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/escheme.rb +0 -114
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine/optimized.rb +0 -127
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/engine.rb +0 -120
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/enhancer.rb +0 -723
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/error.rb +0 -23
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/evaluator.rb +0 -88
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/generator.rb +0 -85
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helper.rb +0 -47
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_form_helper.rb +0 -197
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/helpers/rails_helper.rb +0 -353
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/local-setting.rb +0 -9
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/main.rb +0 -516
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/preprocessing.rb +0 -58
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/tiny.rb +0 -144
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis/util.rb +0 -22
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/lib/erubis.rb +0 -73
- data/bundle/ruby/3.2.0/gems/erubis-2.7.0/setup.rb +0 -1331
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/creole.rb +0 -16
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/csv.rb +0 -53
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/erb.rb +0 -65
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/kramdown.rb +0 -13
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/liquid.rb +0 -37
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/pandoc.rb +0 -39
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/radius.rb +0 -41
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdiscount.rb +0 -23
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rdoc.rb +0 -11
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcarpet.rb +0 -31
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/redcloth.rb +0 -13
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/rst-pandoc.rb +0 -10
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/slim.rb +0 -5
- data/bundle/ruby/3.2.0/gems/tilt-2.6.1/lib/tilt/yajl.rb +0 -81
- data/lib/brakeman/parsers/erubis_patch.rb +0 -11
- data/lib/brakeman/parsers/rails2_erubis.rb +0 -9
- data/lib/brakeman/parsers/rails2_xss_plugin_erubis.rb +0 -52
- data/lib/brakeman/parsers/rails3_erubis.rb +0 -85
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/COPYING +0 -0
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_emacs_org.rb +0 -0
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_handlebars.rb +0 -0
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_jbuilder.rb +0 -0
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/_org.rb +0 -0
- /data/bundle/ruby/3.2.0/gems/{tilt-2.6.1 → tilt-2.7.0}/lib/tilt/cli.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a39689acbc7c9a29664a0094c4a3d17933f5ad41220d7035d1e6764e0dea5760
|
|
4
|
+
data.tar.gz: 58ca20c706a0d9c19f422c8e9a63cc81fe65c3f0f6643210315ea64fe911ddac
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0d880a68afaa34c5efe25c07e9a236b5b08c68ad815c3f020bcbe666c42d5538938a428f0c09c9a1b843b4a98431bf020029931e090c6ebb53f04a3bb99fb743
|
|
7
|
+
data.tar.gz: 8a08f92273ea6f270f565bf4fd09cb6d811fbf517314f26ce595207f8473696e1a72e15cbd8aae2b79e29a27df93699063b53ae079b24e256106babefeec1da7
|
data/CHANGES.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
# 8.0.0 - 2026-01-29
|
|
2
|
+
|
|
3
|
+
* No longer produce weak dynamic render path warnings
|
|
4
|
+
* `--skip-libs` removed
|
|
5
|
+
* `--index-libs` removed
|
|
6
|
+
* Revamp of scan progress output and logging
|
|
7
|
+
* Faster file globbing for templates (Mikael Henriksson)
|
|
8
|
+
* Fix singleton method prefixes (viralpraxis)
|
|
9
|
+
* Fix qualified constant lookup to respect module/class context (Mike Dalessio)
|
|
10
|
+
* Replace Erubis with Erubi
|
|
11
|
+
|
|
1
12
|
# 7.1.2 - 2025-12-25
|
|
2
13
|
|
|
3
14
|
* Update `ruby_parser` to remove version restriction (Chedli Bourguiba)
|
data/README.md
CHANGED
|
@@ -75,7 +75,7 @@ To specify an output file for the results:
|
|
|
75
75
|
|
|
76
76
|
brakeman -o output_file
|
|
77
77
|
|
|
78
|
-
The output format is determined by the file extension or by using the `-f` option. Current options are: `text`, `html`, `tabs`, `json`, `junit`, `markdown`, `csv`, `codeclimate`, `github` and `sonar`.
|
|
78
|
+
The output format is determined by the file extension or by using the `-f` option. Current options are: `text`, `html`, `tabs`, `json`, `junit`, `markdown`, `csv`, `codeclimate`, `github`, `sarif`, and `sonar`.
|
|
79
79
|
|
|
80
80
|
Multiple output files can be specified:
|
|
81
81
|
|
data/bundle/load.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
path = File.expand_path('../..', __FILE__)
|
|
2
2
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/csv-3.3.5/lib"
|
|
3
|
-
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/
|
|
3
|
+
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/erubi-1.13.1/lib"
|
|
4
4
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/haml-6.4.0/lib"
|
|
5
5
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/highline-3.1.2/lib"
|
|
6
6
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/parallel-1.27.0/lib"
|
|
@@ -12,6 +12,6 @@ $:.unshift "#{path}/bundle/ruby/3.2.0/gems/sexp_processor-4.17.5/lib"
|
|
|
12
12
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/slim-5.2.1/lib"
|
|
13
13
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/temple-0.10.4/lib"
|
|
14
14
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/terminal-table-4.0.0/lib"
|
|
15
|
-
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/tilt-2.
|
|
15
|
+
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/tilt-2.7.0/lib"
|
|
16
16
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/unicode-display_width-3.2.0/lib"
|
|
17
17
|
$:.unshift "#{path}/bundle/ruby/3.2.0/gems/unicode-emoji-4.2.0/lib"
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
=== 1.13.1 (2024-12-19)
|
|
2
|
+
|
|
3
|
+
* Avoid spurious frozen string literal warnings for chilled strings when using Ruby 3.4 (jeremyevans)
|
|
4
|
+
|
|
5
|
+
=== 1.13.0 (2024-06-13)
|
|
6
|
+
|
|
7
|
+
* Define Erubi.h as a module function (jeremyevans)
|
|
8
|
+
|
|
9
|
+
* Add erubi/capture_block, supporting capturing block output via standard <%= and <%== tags (jeremyevans)
|
|
10
|
+
|
|
11
|
+
=== 1.12.0 (2022-12-22)
|
|
12
|
+
|
|
13
|
+
* Use erb/escape for faster html escaping if available (jeremyevans)
|
|
14
|
+
|
|
15
|
+
* Default :freeze_template_literals option to false if running with --enable-frozen-string-literal (casperisfine) (#35)
|
|
16
|
+
|
|
17
|
+
=== 1.11.0 (2022-08-02)
|
|
18
|
+
|
|
19
|
+
* Support :freeze_template_literals option for configuring whether to add .freeze to template literal strings (casperisfine) (#33)
|
|
20
|
+
|
|
21
|
+
* Support :chain_appends option for chaining appends to the buffer variable (casperisfine, jeremyevans) (#32)
|
|
22
|
+
|
|
23
|
+
* Avoid unnecessary defined? usage on Ruby 3+ when using the :ensure option (jeremyevans)
|
|
24
|
+
|
|
25
|
+
=== 1.10.0 (2020-11-13)
|
|
26
|
+
|
|
27
|
+
* Improve template parsing, mostly by reducing allocations (jeremyevans)
|
|
28
|
+
|
|
29
|
+
* Do not ship tests in the gem, reducing gem size about 20% (jeremyevans)
|
|
30
|
+
|
|
31
|
+
* Support :literal_prefix and :literal_postfix options for how to output literal tags (e.g. <%% code %>) (jaredcwhite) (#26, #27)
|
|
32
|
+
|
|
33
|
+
=== 1.9.0 (2019-09-25)
|
|
34
|
+
|
|
35
|
+
* Change default :bufvar from 'String.new' to '::String.new' to work with BasicObject (jeremyevans)
|
|
36
|
+
|
|
37
|
+
=== 1.8.0 (2018-12-18)
|
|
38
|
+
|
|
39
|
+
* Support :yield_returns_buffer option in capture_end for always returning the (potentially modified) buffer in <%|= tags (evanleck) (#15)
|
|
40
|
+
|
|
41
|
+
=== 1.7.1 (2018-03-05)
|
|
42
|
+
|
|
43
|
+
* Make whitespace handling for <%# %> tags more compatible with Erubis (jeremyevans) (#14)
|
|
44
|
+
|
|
45
|
+
=== 1.7.0 (2017-10-09)
|
|
46
|
+
|
|
47
|
+
* Fix escaping in erubi/capture_end, the setting was previously inverted (jeremyevans) (#10)
|
|
48
|
+
|
|
49
|
+
=== 1.6.1 (2017-06-27)
|
|
50
|
+
|
|
51
|
+
* Fix usage on newer versions of JRuby 9.1 (jeremyevans)
|
|
52
|
+
|
|
53
|
+
=== 1.6.0 (2017-02-27)
|
|
54
|
+
|
|
55
|
+
* Use cgi/escape if available for 6x faster HTML escaping (k0kubun, jeremyevans) (#4)
|
|
56
|
+
|
|
57
|
+
=== 1.5.0 (2017-01-26)
|
|
58
|
+
|
|
59
|
+
* Drop tilt/erubi file, as tilt now ships with Erubi support (jeremyevans)
|
|
60
|
+
|
|
61
|
+
* Drop erubi/capture file, Erubi::CaptureEngine support (jeremyevans)
|
|
62
|
+
|
|
63
|
+
=== 1.4.0 (2017-01-20)
|
|
64
|
+
|
|
65
|
+
* Allow postambles to depend on internal state of engine (jeremyevans)
|
|
66
|
+
|
|
67
|
+
* Allow overriding of behavior for <%= and <%== tags to depend on which indicator was used (jeremyevans)
|
|
68
|
+
|
|
69
|
+
* Make whitespace handling for <% %> tags more compatible with Erubis for subclasses overriding add_text (jeremyevans)
|
|
70
|
+
|
|
71
|
+
=== 1.3.0 (2016-12-29)
|
|
72
|
+
|
|
73
|
+
* Support :capture=>:explicit option in tilt support to use Erubi::CaptureEndEngine (jeremyevans)
|
|
74
|
+
|
|
75
|
+
* Add erubi/capture_end containing Erubi::CaptureEndEngine, allowing <%|= and <%|== for opening capture tags, and <%| for closing capture tags (jeremyevans)
|
|
76
|
+
|
|
77
|
+
=== 1.2.1 (2016-11-21)
|
|
78
|
+
|
|
79
|
+
* Don't automatically freeze template text strings on ruby 1.9 or 2.0 (jeremyevans)
|
|
80
|
+
|
|
81
|
+
=== 1.2.0 (2016-11-21)
|
|
82
|
+
|
|
83
|
+
* Engine#src now returns a frozen string (jeremyevans)
|
|
84
|
+
|
|
85
|
+
* Automatically freeze template text strings on ruby 2.1+, reducing garbage generated (jeremyevans)
|
|
86
|
+
|
|
87
|
+
* Allow overriding of behavior for <%= and <%== tags (ujifgc) (#1)
|
|
88
|
+
|
|
89
|
+
=== 1.1.0 (2016-11-14)
|
|
90
|
+
|
|
91
|
+
* Add :ensure option to supporting restoring bufvar to original value (jeremyevans)
|
|
92
|
+
|
|
93
|
+
* Don't have tilt support require erb (jeremyevans)
|
|
94
|
+
|
|
95
|
+
* Support :engine_class option in tilt support to override engine class used (jeremyevans)
|
|
96
|
+
|
|
97
|
+
* Support :capture option in tilt support to use Erubi::CaptureEngine (jeremyevans)
|
|
98
|
+
|
|
99
|
+
* Add erubi/capture file containing Erubi::CaptureEngine, allowing <%|= and <%|== for capture (and escaping) blocks in templates (jeremyevans)
|
|
100
|
+
|
|
101
|
+
* Raise ArgumentError if template source code contains indicators matched by regexp but not handled (jeremyevans)
|
|
102
|
+
|
|
103
|
+
* Add :bufval option to support arbitrary buffer values (jeremyevans)
|
|
104
|
+
|
|
105
|
+
* Add :regexp option to specify regexp used for scanning (jeremyevans)
|
|
106
|
+
|
|
107
|
+
* Add :src option to specify initial template source (jeremyevans)
|
|
108
|
+
|
|
109
|
+
=== 1.0.0 (2016-11-10)
|
|
110
|
+
|
|
111
|
+
* Initial Public Release
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
= Erubi
|
|
2
|
+
|
|
3
|
+
Erubi is a ERB template engine for ruby. It is a simplified fork of Erubis, using
|
|
4
|
+
the same basic algorithm, with the following differences:
|
|
5
|
+
|
|
6
|
+
* Handles postfix conditionals when using escaping (e.g. <tt><%= foo if bar %></tt>)
|
|
7
|
+
* Supports frozen_string_literal: true in templates via :freeze option
|
|
8
|
+
* Works with ruby's <tt>--enable-frozen-string-literal</tt> option
|
|
9
|
+
* Automatically freezes strings for template text when ruby optimizes it (on ruby 2.1+)
|
|
10
|
+
* Escapes <tt>'</tt> (apostrophe) when escaping for better XSS protection
|
|
11
|
+
* Has 15x-6x faster escaping by using erb/escape or cgi/escape
|
|
12
|
+
* Has 81% smaller memory footprint (calculated using +ObjectSpace.memsize_of_all+)
|
|
13
|
+
* Does no monkey patching (Erubis adds a method to Kernel)
|
|
14
|
+
* Uses an immutable design (all options passed to the constructor, which returns a frozen object)
|
|
15
|
+
* Has simpler internals (1 file, <150 lines of code)
|
|
16
|
+
* Is not dead (Erubis hasn't been updated since 2011)
|
|
17
|
+
|
|
18
|
+
It is not designed with Erubis API compatibility in mind, though most Erubis
|
|
19
|
+
ERB syntax works, with the following exceptions:
|
|
20
|
+
|
|
21
|
+
* No support for <tt><%===</tt> for debug output
|
|
22
|
+
|
|
23
|
+
= Installation
|
|
24
|
+
|
|
25
|
+
gem install erubi
|
|
26
|
+
|
|
27
|
+
= Source Code
|
|
28
|
+
|
|
29
|
+
Source code is available on GitHub at https://github.com/jeremyevans/erubi
|
|
30
|
+
|
|
31
|
+
= Usage
|
|
32
|
+
|
|
33
|
+
Erubi only has built in support for retrieving the generated source for a
|
|
34
|
+
file:
|
|
35
|
+
|
|
36
|
+
require 'erubi'
|
|
37
|
+
eval(Erubi::Engine.new(File.read('filename.erb')).src)
|
|
38
|
+
|
|
39
|
+
Most users will probably use Erubi via Rails or Tilt. Erubi is the default
|
|
40
|
+
erb template handler in Tilt 2.0.6+ and Rails 5.1+.
|
|
41
|
+
|
|
42
|
+
== Capturing
|
|
43
|
+
|
|
44
|
+
Erubi does not support capturing block output into the template by default.
|
|
45
|
+
It currently ships with two implementations that allow it.
|
|
46
|
+
|
|
47
|
+
=== Erubi::CaptureBlockEngine
|
|
48
|
+
|
|
49
|
+
The recommended implementation can be required via +erubi/capture_block+,
|
|
50
|
+
which allows capturing to work with normal <tt><%=</tt> and <tt><%==</tt>
|
|
51
|
+
tags.
|
|
52
|
+
|
|
53
|
+
<%= form do %>
|
|
54
|
+
<input>
|
|
55
|
+
<% end %>
|
|
56
|
+
|
|
57
|
+
When using the capture_block support, capture methods should just return
|
|
58
|
+
the text it emit into the template, and call +capture+ on the buffer value.
|
|
59
|
+
Since the buffer variable is a local variable and not an instance variable
|
|
60
|
+
by default, you'll probably want to set the +:bufvar+ variable when using
|
|
61
|
+
the capture_block support to an instance variable, and have any methods
|
|
62
|
+
used call capture on that instance variable. Example:
|
|
63
|
+
|
|
64
|
+
def form(&block)
|
|
65
|
+
"<form>#{@_buf.capture(&block)}</form>"
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
puts eval(Erubi::CaptureBlockEngine.new(<<-END, bufvar: '@_buf', trim: false).src)
|
|
69
|
+
before
|
|
70
|
+
<%= form do %>
|
|
71
|
+
inside
|
|
72
|
+
<% end %>
|
|
73
|
+
after
|
|
74
|
+
END
|
|
75
|
+
|
|
76
|
+
# Output:
|
|
77
|
+
# before
|
|
78
|
+
# <form>
|
|
79
|
+
# inside
|
|
80
|
+
# </form>
|
|
81
|
+
# after
|
|
82
|
+
|
|
83
|
+
To use the capture_block support with tilt:
|
|
84
|
+
|
|
85
|
+
require 'tilt'
|
|
86
|
+
require 'erubi/capture_block'
|
|
87
|
+
Tilt.new("filename.erb", :engine_class=>Erubi::CaptureBlockEngine).render
|
|
88
|
+
|
|
89
|
+
Note that the capture_block support, while very compatible with the default
|
|
90
|
+
support, is not 100% compatible. One area where behavior differs is when
|
|
91
|
+
using multiple statements inside <tt><%=</tt> and <tt><%==</tt> tags:
|
|
92
|
+
|
|
93
|
+
<%= 1; 2 %>
|
|
94
|
+
|
|
95
|
+
The default support will output 2, but the capture_block support will output
|
|
96
|
+
1.
|
|
97
|
+
|
|
98
|
+
=== Erubi::CaptureEndEngine
|
|
99
|
+
|
|
100
|
+
An alternative capture implementation can be required via +erubi/capture_end+,
|
|
101
|
+
which supports it via <tt><%|=</tt> and <tt><%|==</tt> tags which are
|
|
102
|
+
closed with a <tt><%|</tt> tag:
|
|
103
|
+
|
|
104
|
+
<%|= form do %>
|
|
105
|
+
<input>
|
|
106
|
+
<%| end %>
|
|
107
|
+
|
|
108
|
+
It is only recommended to use +erubi/capture_end+ for backwards
|
|
109
|
+
compatibilty.
|
|
110
|
+
|
|
111
|
+
When using the capture_end support, capture methods (such as +form+ in the example
|
|
112
|
+
above) should return the (potentially modified) buffer. Similar to the
|
|
113
|
+
capture_block support, using an instance variable is recommended. Example:
|
|
114
|
+
|
|
115
|
+
def form
|
|
116
|
+
@_buf << "<form>"
|
|
117
|
+
yield
|
|
118
|
+
@_buf << "</form>"
|
|
119
|
+
@_buf
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
puts eval(Erubi::CaptureEndEngine.new(<<-END, bufvar: '@_buf').src)
|
|
123
|
+
before
|
|
124
|
+
<%|= form do %>
|
|
125
|
+
inside
|
|
126
|
+
<%| end %>
|
|
127
|
+
after
|
|
128
|
+
END
|
|
129
|
+
|
|
130
|
+
# Output:
|
|
131
|
+
# before
|
|
132
|
+
# <form>
|
|
133
|
+
# inside
|
|
134
|
+
# </form>
|
|
135
|
+
# after
|
|
136
|
+
|
|
137
|
+
Alternatively, passing the option <tt>:yield_returns_buffer => true</tt> will return the
|
|
138
|
+
buffer captured by the block instead of the last expression in the block.
|
|
139
|
+
|
|
140
|
+
= Reporting Bugs
|
|
141
|
+
|
|
142
|
+
The bug tracker is located at https://github.com/jeremyevans/erubi/issues
|
|
143
|
+
|
|
144
|
+
= License
|
|
145
|
+
|
|
146
|
+
MIT
|
|
147
|
+
|
|
148
|
+
= Authors
|
|
149
|
+
|
|
150
|
+
Jeremy Evans <code@jeremyevans.net>
|
|
151
|
+
kuwata-lab.com
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erubi'
|
|
4
|
+
|
|
5
|
+
module Erubi
|
|
6
|
+
# An engine class that supports capturing blocks via the <tt><%=</tt> and <tt><%==</tt> tags:
|
|
7
|
+
#
|
|
8
|
+
# <%= upcase_form do %>
|
|
9
|
+
# <%= 'foo' %>
|
|
10
|
+
# <% end %>
|
|
11
|
+
#
|
|
12
|
+
# Where +upcase_form+ is defined like:
|
|
13
|
+
#
|
|
14
|
+
# def upcase_form(&block)
|
|
15
|
+
# "<form>#{@bufvar.capture(&block).upcase}</form>"
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# With output being:
|
|
19
|
+
#
|
|
20
|
+
# <form>
|
|
21
|
+
# FOO
|
|
22
|
+
# </form>
|
|
23
|
+
#
|
|
24
|
+
# This requires using a string subclass as the buffer value, provided by the
|
|
25
|
+
# CaptureBlockEngine::Buffer class.
|
|
26
|
+
#
|
|
27
|
+
# This engine does not support the :escapefunc option. To change the escaping function,
|
|
28
|
+
# use a subclass of CaptureBlockEngine::Buffer and override the #| method.
|
|
29
|
+
#
|
|
30
|
+
# This engine does not support the :chain_appends option, and ignores it if present.
|
|
31
|
+
class CaptureBlockEngine < Engine
|
|
32
|
+
class Buffer < ::String
|
|
33
|
+
|
|
34
|
+
# Convert argument to string when concatening
|
|
35
|
+
def <<(v)
|
|
36
|
+
concat(v.to_s)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Escape argument using Erubi.h then then concatenate it to the receiver.
|
|
40
|
+
def |(v)
|
|
41
|
+
concat(h(v))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Temporarily clear the receiver before yielding to the block, yield the
|
|
45
|
+
# given args to the block, return any data captured by the receiver, and
|
|
46
|
+
# restore the original data the receiver contained before returning.
|
|
47
|
+
def capture(*args)
|
|
48
|
+
prev = dup
|
|
49
|
+
replace("") # 1.8 support!
|
|
50
|
+
yield(*args)
|
|
51
|
+
dup
|
|
52
|
+
ensure
|
|
53
|
+
replace(prev)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
if RUBY_VERSION >= '2'
|
|
59
|
+
define_method(:h, ::Erubi.instance_method(:h))
|
|
60
|
+
# :nocov:
|
|
61
|
+
else
|
|
62
|
+
def h(v)
|
|
63
|
+
::Erubi.h(v)
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
# :nocov:
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def initialize(input, properties={})
|
|
70
|
+
properties = Hash[properties]
|
|
71
|
+
properties[:bufval] ||= '::Erubi::CaptureBlockEngine::Buffer.new'
|
|
72
|
+
properties[:chain_appends] = false
|
|
73
|
+
super
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
def add_expression_result(code)
|
|
79
|
+
add_expression_op(' <<= ', code)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def add_expression_result_escaped(code)
|
|
83
|
+
add_expression_op(' |= ', code)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def add_expression_op(op, code)
|
|
87
|
+
check = /\A\s*\z/.send(MATCH_METHOD, code) ? "''" : ''
|
|
88
|
+
with_buffer{@src << op << check << code}
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'erubi'
|
|
4
|
+
|
|
5
|
+
module Erubi
|
|
6
|
+
# An engine class that supports capturing blocks via the <tt><%|=</tt> and <tt><%|==</tt> tags,
|
|
7
|
+
# explicitly ending the captures using <tt><%|</tt> end <tt>%></tt> blocks.
|
|
8
|
+
class CaptureEndEngine < Engine
|
|
9
|
+
# Initializes the engine. Accepts the same arguments as ::Erubi::Engine, and these
|
|
10
|
+
# additional options:
|
|
11
|
+
# :escape_capture :: Whether to make <tt><%|=</tt> escape by default, and <tt><%|==</tt> not escape by default,
|
|
12
|
+
# defaults to the same value as :escape.
|
|
13
|
+
# :yield_returns_buffer :: Whether to have <tt><%|</tt> tags insert the buffer as an expression, so that
|
|
14
|
+
# <tt><%| end %></tt> tags will have the buffer be the last expression inside
|
|
15
|
+
# the block, and therefore have the buffer be returned by the yield
|
|
16
|
+
# expression. Normally the buffer will be returned anyway, but there
|
|
17
|
+
# are cases where the last expression will not be the buffer,
|
|
18
|
+
# and therefore a different object will be returned.
|
|
19
|
+
def initialize(input, properties={})
|
|
20
|
+
properties = Hash[properties]
|
|
21
|
+
escape = properties.fetch(:escape){properties.fetch(:escape_html, false)}
|
|
22
|
+
@escape_capture = properties.fetch(:escape_capture, escape)
|
|
23
|
+
@yield_returns_buffer = properties.fetch(:yield_returns_buffer, false)
|
|
24
|
+
@bufval = properties[:bufval] ||= '::String.new'
|
|
25
|
+
@bufstack = '__erubi_stack'
|
|
26
|
+
properties[:regexp] ||= /<%(\|?={1,2}|-|\#|%|\|)?(.*?)([-=])?%>([ \t]*\r?\n)?/m
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# Handle the <%|= and <%|== tags
|
|
33
|
+
def handle(indicator, code, tailch, rspace, lspace)
|
|
34
|
+
case indicator
|
|
35
|
+
when '|=', '|=='
|
|
36
|
+
rspace = nil if tailch && !tailch.empty?
|
|
37
|
+
add_text(lspace) if lspace
|
|
38
|
+
escape_capture = !((indicator == '|=') ^ @escape_capture)
|
|
39
|
+
terminate_expression
|
|
40
|
+
@src << "begin; (#{@bufstack} ||= []) << #{@bufvar}; #{@bufvar} = #{@bufval}; #{@bufstack}.last << #{@escapefunc if escape_capture}((" << code
|
|
41
|
+
@buffer_on_stack = false
|
|
42
|
+
add_text(rspace) if rspace
|
|
43
|
+
when '|'
|
|
44
|
+
rspace = nil if tailch && !tailch.empty?
|
|
45
|
+
add_text(lspace) if lspace
|
|
46
|
+
if @yield_returns_buffer
|
|
47
|
+
terminate_expression
|
|
48
|
+
@src << " #{@bufvar}; "
|
|
49
|
+
end
|
|
50
|
+
@src << code << ")).to_s; ensure; #{@bufvar} = #{@bufstack}.pop; end;"
|
|
51
|
+
@buffer_on_stack = false
|
|
52
|
+
add_text(rspace) if rspace
|
|
53
|
+
else
|
|
54
|
+
super
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|