Conversation
It named nil/true/false by their class, and reaching input.class at all raised NoMethodError for a BasicObject rather than TypeError. Let core build the message, as the C extension does.
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.
string_valueis documented as "Like StringValue in C" (lib/cgi/escape.rb:235), but#{input.class}differs from it two ways:The second one matters more than the message: a
rescue TypeErrorthat works with the extension does not catch without it.lib/cgi/escape.rb:167-168skips the C extension on TruffleRuby, so that engine always takes this path. Confirmed on truffleruby 3.3.7 —CGI.escapeHTMLresolves toCGI::Escape, and both rows above reproduce.Letting
String#+do the conversion makes core raise exactly what the extension raises.String === inputreturns the argument untouched for strings and subclasses, so there is no extra allocation on the common path, and it never calls a method on the object — which is what keepsBasicObjectaTypeError.The test goes in
CGIEscapePureRubyTest, which removes the C methods insetupand therefore covers the fallback on every engine. #131's ownnilassertions are inCGIEscapeTest, which on CRuby exercises the C path — that is why this shipped untested.Verification
Run on truffleruby 3.3.7, the engine that always uses this path:
masternilbut keepinput.classfor the resttruerowString.try_convert(input) || ("" + input)BasicObjectThat last row is worth a note:
String.try_convertitself callsrespond_to?on TruffleRuby, so it raisesNoMethodErrorbefore any fallback can run. Keepingtry_convertin the expression looks equivalent and is not, on the one engine this fix is for.CRuby 3.2.11: same red/green, and the full file goes 442 → 443 tests with 0 failures. (3 errors on both pristine and fixed —
RbConfig::LIMITSandassert_separately, because I ran the file directly rather than throughtest/lib/helper.rb.)Behaviour table against the extension, both engines:
StringandStringsubclasses come back as the same object,to_strobjects convert, andnil/true/false/Integer/BasicObjectall raise the extension's exactTypeErrormessage.I did not run the jruby row; its escape backend is the Java extension, and
CGI::Escapeis only reached there when that is absent.Unrelated to this, I have #136 open on the same file — different method, no textual overlap, and either order works.
Disclosure: I used Claude (an AI assistant) while preparing this change.