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

Fix method name validation edge-case #1045

Merged
merged 2 commits into from
Jul 7, 2022
Merged

Conversation

paracycle
Copy link
Member

@paracycle paracycle commented Jul 7, 2022

Motivation

Fixes #1042

It turns out that :4_to_5= is not a valid symbol but "4_to_5=".to_sym does not quote it and represents it as :4_to_5= instead of :"4_to_5", which throws off our whole method name validation logic.

The behaviour of Ruby was correct on this symbol until ruby-2.2.0-preview2, after which it was broken:

$ docker run --rm -e "ALL_RUBY_SINCE=ruby-2.0" rubylang/all-ruby ./all-ruby -e "puts '4_to_5='.to_sym.inspect"
ruby-2.0.0-p0       :"4_to_5="
...
ruby-2.2.0-preview1 :"4_to_5="
ruby-2.2.0-preview2 :4_to_5=
...
ruby-3.2.0-preview1 :4_to_5=

I think it is related to this change: ruby/ruby@986a893

Implementation

The fix is to check validity of the name after stripping trailing = as well. That leaves == as an edge-case, that we handle separately.

Tests

Improved existing tests and added explicit AR column tests for invalid method named column names

@paracycle paracycle requested review from Morriar and a team July 7, 2022 21:40
It turns out that `:4_to_5=` is not a valid symbol but `"4_to_5=".to_sym`
does not quote it and represents it as `:4_to_5=`, which throws off our
whole method name validation logic.

The fix is to check validity of the name after stripping trailing `=`
as well. That leaves `==` as an edge-case, that we handle separately.
@paracycle paracycle force-pushed the uk-fix-method-name-validation branch from af49ba7 to 75f6857 Compare July 7, 2022 23:23
@paracycle paracycle merged commit 8c2af97 into main Jul 7, 2022
@paracycle paracycle deleted the uk-fix-method-name-validation branch July 7, 2022 23:36
@shopify-shipit shopify-shipit bot temporarily deployed to production July 14, 2022 18:56 Inactive
paracycle added a commit that referenced this pull request Jul 18, 2022
Our current way of doing method name and parameter name checks are a bit
hacky and [that's been showing through](#1045).

A better way to do this is to use the compiler to do the name checks,
similar to [how Ruby does it in its codebase](https://github.com/ruby/ruby/blob/241dced625f9ba8a4071954579778a0940e75179/ext/rubyvm/lib/forwardable/impl.rb#L3-L9).

This method relies on compiling a method definition with the given name
and then checking if the compiled code actually defines a method with
that name.
paracycle added a commit that referenced this pull request Jul 18, 2022
Our current way of doing method name and parameter name checks are a bit
hacky and [that's been showing through](#1045).

A better way to do this is to use the compiler to do the name checks,
similar to [how Ruby does it in its codebase](https://github.com/ruby/ruby/blob/241dced625f9ba8a4071954579778a0940e75179/ext/rubyvm/lib/forwardable/impl.rb#L3-L9).

This method relies on compiling a method definition with the given name
and then checking if the compiled code actually defines a method with
that name.
paracycle added a commit that referenced this pull request Jul 18, 2022
Our current way of doing method name and parameter name checks are a bit
hacky and [that's been showing through](#1045).

A better way to do this is to use the compiler to do the name checks,
similar to [how Ruby does it in its codebase](https://github.com/ruby/ruby/blob/241dced625f9ba8a4071954579778a0940e75179/ext/rubyvm/lib/forwardable/impl.rb#L3-L9).

This method relies on compiling a method definition with the given name
and then checking if the compiled code actually defines a method with
that name.
egiurleo pushed a commit that referenced this pull request Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0.9.0 generates method names starting with digits
3 participants