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

Allow Gem paths to be stripped from file names in stacktraces when they contain a Regexp special character #764

Merged
merged 1 commit into from
Dec 20, 2022

Conversation

imjoehaines
Copy link
Contributor

@imjoehaines imjoehaines commented Dec 19, 2022

Goal

We strip the Gem paths from file names in stack traces, but this doesn't work if there's a regexp special character

For example, the Ruby 3.2 RC contains a '+' in the gem path (at least locally and on CI): /.../.gem/ruby/3.2.0+3

This won't match any paths when used in a Regexp, because it is expecting one or more 0 characters, rather than the literal characters 0+. I've changed this matching logic to use a string instead of a Regexp to sidestep this problem and save having to escape the path

I spent a bit of time looking at adding unit tests for this but decided not to in the end because it involves reaching into Gem internals and, with the wide range of Ruby versions we support, that didn't seem like a good idea. We already have tests for this stripping that use the real Gem path to prove this doesn't break anything

Testing

This caused a test to fail on the Ruby 3.2 RC, which now passes with this change

@imjoehaines imjoehaines changed the title Regexp escape gem path Use Regexp#escape when matching gem paths Dec 19, 2022
@imjoehaines imjoehaines removed the request for review from Cawllec December 20, 2022 09:35
e.g. the 3.2 RC contains a '+' in the gem path (at least locally and on
CI): `/../.gem/ruby/3.2.0+3`

This needs escaping or it won't match any paths because it is expecting
1 or more '0' characters, rather than the literal characters '0+'
@imjoehaines imjoehaines changed the title Use Regexp#escape when matching gem paths Allow Gem paths to be stripped from file names in stacktraces when they contain a Regexp special character Dec 20, 2022
@imjoehaines imjoehaines requested review from Cawllec and twometresteve and removed request for Cawllec December 20, 2022 11:15
@imjoehaines imjoehaines merged commit 491a3e4 into next Dec 20, 2022
@imjoehaines imjoehaines deleted the regexp-escape-gem-path branch December 20, 2022 11:59
@imjoehaines imjoehaines mentioned this pull request Jan 4, 2023
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.

2 participants