-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
Spec ./spec/rspec/support/encoded_string_spec.rb:98 passes on MRI when it shouldn't #163
Comments
There are several other places with |
The following snippet is basically what EncodedString does:
On MRI this returns @brixen You being Mr Encoding himself, does any of the above ring a bell? |
See rspec/rspec-support#163 for the background story.
JRuby 1.17.18 seems to have the same problem, it also returns |
The Besides the comment in the referenced test about the meaning of This can cause some interactions in specs where, for example, the differ spec has a magic comment @yorickpeterse I haven't read the whole history here in great detail. Did you note that I got this spec from rubyspec https://github.com/rubyspec/rubyspec/blob/91ce9f6549/core/string/shared/encode.rb#L12 ? I think the end state of EncodedString conversions will be something like (off the top of my head, ignoring any invalid bytes) if compatible_encoding = Encoding.compatible?(string.encoding, @encoding)
string.encode(compatible_encoding)
elsif compatible_encoding = Encoding.compatible?(string.encoding, Encoding.default_external)
string.encode(compatible_encoding)
else
string.force_encoding(Encoding.default_external) # cannot convert, so force
end (I still haven't fixed the original bug that got me into this rabbit hole..., an ArgumentError on describe '#split' do
context 'when the string has an invalid byte sequence' do
let(:message_with_invalid_byte_sequence) { "\xEF \255 \xAD I have bad bytes".force_encoding(utf8_encoding) }
it 'normally raises an ArgumentError' do
expect {
message_with_invalid_byte_sequence.split("\n")
}.to raise_error(ArgumentError)
end
it 'replaces invalid bytes with the REPLACE string' do
resulting_array = build_encoded_string(message_with_invalid_byte_sequence, utf8_encoding).split("\n")
expect(resulting_array).to match [
a_string_identical_to("? ? ? I have bad bytes")
]
end
end ) |
I believe this has been resolved and may be closed |
See rspec/rspec-support#163 for the background story.
This is an odd case. The spec https://github.com/rspec/rspec-support/blob/master/spec/rspec/support/encoded_string_spec.rb#L98 seems to pass on MRI and fail on Rubinius, but it makes little sense as to why it passes on MRI.
The problem on Rubinius seems to be that it's comparing
"\x80"
with"?"
, both encoded using Emacs-Mule. So see what data is used I "instrumented" the code using good ol'p
:On MRI the output of this test is as following:
On Rubinius the output is as following:
What is interesting here is that the local variable
resulting_string
appears to be correct (per the test), but calling the method used to build this variable's value results in a different string, regardless of calling it before or after the variable assignment.If I only add
p build_encoded_string(string, no_converter_encoding).to_s
to the test it seems to output "?" correctly. This suggests some sort of race condition is going on somewhere. I'm currently trying to see where that might be.The text was updated successfully, but these errors were encountered: