-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Match file paths with spaces in caller regexp #1358
Conversation
duplicate : #1355 |
rats. i searched for the "cache" warning but i guess i didn't search for "spaces". |
you solved it somewhat differently. would you like to merge in changes from the other (mine), or have me add some changes? I don't have failing tests for the difference between the two regexen |
(As a maintainer, I'd rather someone else get credit...) |
Great, I was hoping someone would fix the spaces situation. Thanks 👍 |
e105eb6
to
3354c9e
Compare
After fiddling with some extra tests I think your pattern is more accurate. My original thinking was that the string after the file path (an error message) could include a substring match. in which case the greedy regexp is more correct. An example that passes for non-greedy and fails for greedy: def test_serializer_file_path_with_path_in_string
# $ ruby =(echo $'def foo(s); raise s; end;\nfoo("file:123:in string")')
# /tmp/zshr2gfAE:1:in `foo': file:123:in string (RuntimeError)
# from /tmp/zshr2gfAE:2:in `<main>'
path = '/Users/git/ember js/ember-crm-backend/app/serializers/lead_serializer.rb'
caller_line = "#{path}:1:in `foo': file:123:in string (RuntimeError)"
assert_equal path, caller_line[ActiveModel::Serializer::CALLER_FILE]
end but as I said, I don't think that's appropriate in this case. So I adjusted mine, added your test, and added an additional (more convoluted) test to confirm the difference between the two. Use whichever pull req makes sense. |
|
||
def test_serializer_file_path_with_submatch | ||
# The submatch in the path ensures we're using a correctly greedy regexp. | ||
path = '/Users/git/ember js/ember:123:in x/app/serializers/lead_serializer.rb' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone has that in their file path I pity them 😺
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, quite.
In my case the file path was generated by another process with apparently little sanitation on the naming ;-)
@rwstauner looks good. Could you add a changelog entry as a Fix? I have a few other comments but nothing big. I keep thinking there should be a way for the subclass to calculate its own digest outside of the inherited hook, which would be simpler, no? I think the method would just need to be dynamically defined |
3354c9e
to
90fa377
Compare
Sounds like a good idea, but we'd have to find another way to get the file from where the class is inheriting (the caller) since the value of |
Match file paths with spaces in caller regexp
Closes #1355 |
Thanks! |
When matching only
\S+
I get warnings like this on my ci server:Matching the trailing space after
:\d+:in
wasn't strictly necessary, but seemed like it would help it to be more accurate.