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

[ruby] Regex Match Defines $N Vars #5303

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

DavidBakerEffendi
Copy link
Collaborator

This PR implements the other component of regex matching defining global variables. In Ruby, $1, $2, etc. correspond to the group matched in the last match. This is synonymous to how a MatchData object could refer to these matches.

This PR models these nref objects to $[1] and, during a match lowering, defines them to the corresponding index position of the lowered temp match object, i.e., $[1] = <tmp-0>[1] where N is determined by the number of opening parenthesis (simple heuristic).

Additionally, the lowered match calls have their methodFullName defined for convenient policy/semantic definition creation.

This PR implements the other component of regex matching defining global variables. In Ruby, `$1`, `$2`, etc. correspond to the group matched in the last match. This is synonymous to how a `MatchData` object could refer to these matches.

This PR models these `nref` objects to `$[1]` and, during a match lowering, defines them to the corresponding index position of the lowered temp match object, i.e., `$[1] = <tmp-0>[1]` where `N` is determined by the number of opening parenthesis (simple heuristic).

Additionally, the lowered `match` calls have their `methodFullName` defined for convenient policy/semantic definition creation.
@DavidBakerEffendi DavidBakerEffendi added the ruby Relates to rubysrc2cpg label Feb 12, 2025
@DavidBakerEffendi DavidBakerEffendi self-assigned this Feb 12, 2025
@DavidBakerEffendi DavidBakerEffendi merged commit c72d37d into master Feb 12, 2025
5 checks passed
@DavidBakerEffendi DavidBakerEffendi deleted the dave/ruby/indexed-group-global-vars branch February 12, 2025 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Relates to rubysrc2cpg
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants