Avoid being slower than the previous version for most cases#30
Merged
Avoid being slower than the previous version for most cases#30
Conversation
This is the same trick used by https://github.com/k0kubun/hescape to choose the best strategy for different scenarios.
nobu
reviewed
Nov 5, 2022
| { | ||
| str = rb_convert_type(str, T_STRING, "String", "to_s"); | ||
| if (!RB_TYPE_P(str, T_STRING)) { | ||
| str = rb_convert_type(str, T_STRING, "String", "to_s"); |
Member
Author
There was a problem hiding this comment.
It calls to_str instead of to_s, right? Almost every template engine calls to_s instead of to_str before passing an object to an HTML escape method, so it needs to be to_s. Note that the previous Ruby implementation of ERB::Util.html_escape called to_s before passing an argument to CGI.escapeHTML too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Benchmark
Test benchmarks in benchmark/cgi_escape_html.yml in ruby/ruby, modified for comparing it with other implementations:
Base benchmark script
Please see the "Other benchmarks" in #29 for the previous results.
No escape ("")
No escape ("abcde")
No escape ("abcde" * 300)
Escaped ("abcd<")
Escaped ("'&"<>")
Escaped ("'&"<>" * 10)
Escaped (example.com)