Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace owasp java encoder with faster implementation #227

Merged
merged 2 commits into from
May 22, 2023

Conversation

casid
Copy link
Owner

@casid casid commented May 21, 2023

Benchmarks as in #225 have shown that OWASP Java Encoder is slower than expected for output escaping. In order to use the faster methods of OWASP encoder, all template outputs had to provide an instance of the rather ancient and clumsy Writer interface, that really should not be part of the public API of TemplateOutput.

This PR replaces the four methods we currently use from the OWASP Java Encoder project by optimized methods that work directly on a TemplateOutput:

  • org.owasp.encoder.Encode.forHtmlContent -> gg.jte.html.escape.Escape.htmlContent
  • org.owasp.encoder.Encode.forHtmlAttribute -> gg.jte.html.escape.Escape.htmlAttribute
  • org.owasp.encoder.Encode.forJavaScriptBlock -> gg.jte.html.escape.Escape.javaScriptBlock
  • org.owasp.encoder.Encode.forJavaScriptAttribute -> gg.jte.html.escape.Escape.javaScriptAttribute

All methods should behave exactly like their OWASP counterparts.

After this patch is merged, jte will be free from external dependencies.

@casid casid self-assigned this May 21, 2023
@codecov
Copy link

codecov bot commented May 21, 2023

Codecov Report

Patch coverage: 95.57% and project coverage change: -0.26 ⚠️

Comparison is base (e397525) 93.02% compared to head (17c033d) 92.77%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #227      +/-   ##
============================================
- Coverage     93.02%   92.77%   -0.26%     
- Complexity     1142     1164      +22     
============================================
  Files            64       65       +1     
  Lines          2912     2991      +79     
  Branches        467      476       +9     
============================================
+ Hits           2709     2775      +66     
- Misses          110      123      +13     
  Partials         93       93              
Impacted Files Coverage Δ
...e-runtime/src/main/java/gg/jte/TemplateOutput.java 100.00% <ø> (ø)
...untime/src/main/java/gg/jte/output/FileOutput.java 77.77% <60.00%> (-7.94%) ⬇️
...time/src/main/java/gg/jte/output/WriterOutput.java 69.23% <60.00%> (-8.55%) ⬇️
...ntime/src/main/java/gg/jte/html/escape/Escape.java 98.79% <98.79%> (ø)
...main/java/gg/jte/html/OwaspHtmlTemplateOutput.java 98.11% <100.00%> (+6.73%) ⬆️
...src/main/java/gg/jte/output/PrintWriterOutput.java 100.00% <100.00%> (ø)
...time/src/main/java/gg/jte/output/StringOutput.java 68.42% <100.00%> (-31.58%) ⬇️
...c/main/java/gg/jte/output/Utf8ByteArrayOutput.java 100.00% <100.00%> (ø)
...me/src/main/java/gg/jte/output/Utf8ByteOutput.java 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kelunik
Copy link
Collaborator

kelunik commented May 21, 2023

This likely needs to be 3.0 then, because of the breaking change to the interface?

@casid casid changed the title #225 replace owasp java encoder with faster implementation Replace owasp java encoder with faster implementation May 22, 2023
@casid casid mentioned this pull request May 22, 2023
@casid
Copy link
Owner Author

casid commented May 22, 2023

This likely needs to be 3.0 then, because of the breaking change to the interface?

I think you are right, there are quite a few things that accumulated for a new major version. I've created a ticket to collect all changes in one place: #230

@casid casid merged commit f69259c into main May 22, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants