-
-
Notifications
You must be signed in to change notification settings - Fork 760
Handle exception message with invalid UTF-8; For rbx #1760
Conversation
Can you add a spec for this? I'd like to see one exposing/demonstrating the problem here. |
Also this won't work for Ruby 1.8, (we typically conditionally define methods like this based on the existance of the encode method), and won't work for charsets that aren't UTF-8 |
@JonRowe trying to figure out how write a spec for it. My first goal was to prove I didn't break anything :) I'll fix the 1.8 compatibility with next push. |
It's tricky to write a string literal with an invalid byte sequence. My suggestion is to use |
@myronmarston I can write such a string, the hard thing is to figure out why |
That's trickier. However, while the bug only manifested for you on rbx, I expect that the same bug would manifest on MRI given the "right" string. I'd rather have a spec that demonstrates the bug on MRI than a spec that only demonstrates it on RBX, particularly since we have RBX in the "allowed failures" section of our travis builds. (We've invested countless hours in getting RBX builds to pass but it continues to cause us problems...) |
I'd also like to see a spec demonstrating how this reacts with a UTF-8 incompatible encoding scheme (we have similar specs for this in our differ specs, which is now in the support gem) |
@myronmarston I understand. Any tricks to getting all specs to pass in dev? Do you mostly follow the steps in the Also, zounds, rbx is green with failures! https://travis-ci.org/rspec/rspec-core/jobs/39887273#L125 |
Do you have a |
@myronmarston All specs pass now that I've blanked out my
Now I can work on trying to reproduce the original bug and test drive the fix. |
Ok, I give up. @brixen, how do I disable rbx-(VM?)-specific stack traces so that they'll be similar to MRI? I assume it's a e.g. failures RuntimeError:
foo
- # (erb):1:in `<main>'
- # ./spec/rspec/core/resources/formatter_specs.rb:39:in `block (2 levels) in <top (required)>'
+ # (erb):1:in `__script__'
+ # kernel/common/block_environment.rb:53:in `call_on_instance'
+ # kernel/common/eval.rb:176:in `eval'
+ # /Users/benjamin/.rvm/rubies/rbx-2.2.6/gems/gems/rubysl-erb-2.0.1/lib/rubysl/erb/erb.rb:849:in `result'
+ # ./spec/rspec/core/resources/formatter_specs.rb:39:in `__script__'
+ # kernel/common/eval.rb:101:in `instance_exec'
+ # kernel/bootstrap/array.rb:87:in `map'
# ./spec/support/sandboxing.rb:31:in `run'
+ # kernel/bootstrap/array.rb:87:in `map'
# ./spec/support/formatter_support.rb:13:in `run_example_specs_with_formatter'
- # ./spec/support/sandboxing.rb:2:in `block (3 levels) in <top (required)>'
- # ./spec/support/sandboxing.rb:36:in `instance_exec'
- # ./spec/support/sandboxing.rb:36:in `block in sandboxed'
+ # kernel/common/eval.rb:101:in `instance_exec'
+ # kernel/bootstrap/proc.rb:20:in `call'
+ # ./spec/support/sandboxing.rb:2:in `__script__'
+ # kernel/common/eval.rb:101:in `instance_exec'
+ # ./spec/support/sandboxing.rb:36:in `sandboxed'
# ./spec/support/sandboxing.rb:35:in `sandboxed'
- # ./spec/support/sandboxing.rb:2:in `block (2 levels) in <top (required)>'
+ # ./spec/support/sandboxing.rb:2:in `__script__'
+ # kernel/common/eval.rb:101:in `instance_exec'
+ # kernel/bootstrap/proc.rb:20:in `call'
+ # kernel/bootstrap/array.rb:87:in `map'
+ # kernel/bootstrap/array.rb:87:in `map'
+ # kernel/common/kernel.rb:447:in `load'
+ # kernel/delta/code_loader.rb:66:in `load_script'
+ # kernel/delta/code_loader.rb:152:in `load_script'
+ # kernel/loader.rb:649:in `script'
+ # kernel/loader.rb:831:in `main' |
@bf4 -- I think we can just skip those specs on RBX (or write a different fixture for RBX that uses the RBX backtraces). BTW, we should probably fix our specs so they are not prone to failing when contributors have stuff in |
@bf4 we would strongly encourage not filtering backtraces. It removes valuable information. MRI backtraces are an artifact of being written in C where no frame information is available. If the backtrace runs through some Ruby code in eg standard library, those frames would be included. Related, instead of mining backtrace string text for information, we should be making proper exception objects with attributes. In both these cases (ie filtering and accessing attributes in an object-oriented fashion), if you want to help us create APIs, we'd be happy to implement them. |
RSpec fixtures are way too magical. It took me a bit* to track down where they were coming from. I think I'm going to just ignore rbx for those specs.
|
What fixtures are you referring to? |
where a failure like I mentioned above on
the expectation is yadda yadda in a HEREDOC in
|
5640d3d
to
b1f019d
Compare
@JonRowe sorry, apparently once you reply via email, you can never format it. I just pushed the code I spiked last week, but I still haven't written the actual test. |
# Converting it to a higher higher character set (UTF-16) and then | ||
# back (to UTF-8) ensures that you will strip away invalid or undefined byte sequences. | ||
encode(Encoding::UTF_16LE, :invalid => :replace, :undef => :replace, :replace => '?'). | ||
encode(Encoding::UTF_8) |
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.
You still haven't fixed this, it will break on 1.8.7.
Yeah no dramas, it's a known flaw with emailed comments :) It's still not apparent what you mean, that method just returns a string so something is comparing it somewhere... but the the setup for the formatter specs is fairly complex so it has been reduced down into support methods, maybe if you added your spec to this we could give you some feedback, we do need a spec to assert this works ok on normal ruby. |
3249f3e
to
8bd3911
Compare
|
8bd3911
to
e5efd86
Compare
I pushed each commit separately. I'm not sure how you want to handle co-ordinating the changes that would go in rspec-support. If you're okay with this here, I'll make a PR there and do whatever you think is best. (Modify the Gemfile?) |
@@ -5,6 +5,8 @@ Feature: Use rspec-core without rspec-mocks or rspec-expectations | |||
available, but rspec-core can be used just fine without either of those | |||
gems installed. | |||
|
|||
# Rubinius stacktrace includes kernel/loader.rb etc. | |||
@unsupported-on-rbx |
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.
Let me know if there's a better way to do this. That tag was already there :)
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.
This is the normal way we skip a scenario on rbx, but I don't understand why you chose to skip this one. It doesn't appear to be related in any way to the encoding bug you ran into, as far as I can see. Can you explain?
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.
So, there were a bunch of failing rbx specs due to backtraces that I fixed in Skip specs with non-mri-compatible backtrace. Also see rspec-support …
. it's technically out of scope of the PR, so I could put that in a second one, if you like. 23f911b
def exception_message | ||
@exception_message ||= begin | ||
string = exception.message.to_s | ||
RSpec::Support::EncodedString.new(string, encoding_of("")) |
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.
Yeah use encoding_of(string)
, that should suffice.
Map string char with invalid encoding to '?' Format identical string expectation to read easier Refs: - rspec/rspec-core#1760 - via rspec#134
Map string char with invalid encoding to '?' Format identical string expectation to read easier Refs: - rspec/rspec-core#1760 - via rspec#134
Map string char with invalid encoding to '?' Format identical string expectation to read easier Refs: - rspec/rspec-core#1760 - via rspec#134 Set to pending for JRuby, opened issue jruby/jruby#2580 that JRuby is the only Ruby that returns "\x80" in place of "?"
166bbd9
to
b234ad4
Compare
Updated now that rspec/rspec-support#172 is merged. @JonRowe I'll need more guidance on the changes you proposed in the encoding_spec.rb re: using a real exception, using I made a separate PR for the skipping backtrace specs on non-mri rubies |
b234ad4
to
64e3278
Compare
@JonRowe @myronmarston re: #1760 (comment) thoughts? |
@bf4 just look at the contents of |
Add spec for exception when failure_lines has a bad encoding
"".split("\n") # => [] nil.to_s.split("\n") # => [] If exception.message is nil, the inner block will not be reached. If it is non-nil, then there's no need to check for nil inside the block.
64e3278
to
62204c8
Compare
Simplified it, I think for the better. |
Looks good, I'm going to merge despite the lack of an Appveyor build because it seems to be playing up. |
Handle exception message with invalid UTF-8; For rbx
Should we backport this to |
Yes, if all the rspec-support changes this depends up on are in rspec-support 3.2.0. (I forget). |
🌈 🎆 👯 The |
Hmm I don't think they have and I'm not sure they all should be so prehaps better to leave this for 3.3 |
Sounds like the right choice. |
…ages Handle exception message with invalid UTF-8; For rbx
[skip ci]
See https://travis-ci.org/mikel/mail/jobs/33707769#L129
To reproduce with just the one test
Update Ultimately the encoding bug was fixed in rspec/rspec-support#172