[#105450] [Ruby master Feature#18228] Add a `timeout` option to `IO.copy_stream` — "byroot (Jean Boussier)" <noreply@...>
SXNzdWUgIzE4MjI4IGhhcyBiZWVuIHJlcG9ydGVkIGJ5IGJ5cm9vdCAoSmVhbiBCb3Vzc2llciku
11 messages
2021/09/27
[ruby-core:105143] [Ruby master Bug#18149] Can't match against strings with special codes within
From:
"jeremyevans0 (Jeremy Evans)" <noreply@...>
Date:
2021-09-03 18:21:48 UTC
List:
ruby-core #105143
Issue #18149 has been updated by jeremyevans0 (Jeremy Evans).
Status changed from Open to Rejected
That's because that is an invalid byte sequence, at least if the string's encoding is UTF-8. If the string's encoding is not UTF-8, it works fine:
```
$ ruby -e 'p "\xFF".encoding'
#<Encoding:ASCII-8BIT>
$ ruby -Ku -e 'p "\xFF".encoding'
#<Encoding:UTF-8>
$ ruby -e 'p "\xFF".match(/\\x/)'
nil
$ ruby -Ku -e 'p "\xFF".match(/\\x/)'
-e:1:in `match': invalid byte sequence in UTF-8 (ArgumentError)
from -e:1:in `match'
from -e:1:in `<main>'
```
You can force the string encoding to binary to avoid the ArgumentError:
```
$ ruby -Ku -e 'p "\xFF".b.match(/\\x/)'
nil
```
So I don't think this is a bug, I believe the behavior is expected.
----------------------------------------
Bug #18149: Can't match against strings with special codes within
https://bugs.ruby-lang.org/issues/18149#change-93550
* Author: chucke (Tiago Cardoso)
* Status: Rejected
* Priority: Normal
* ruby -v: 3.0.1
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
This can be summed up by the following example:
```ruby
"\xFF".match /\\x/
#=> (irb):6:in `match': invalid byte sequence in UTF-8 (ArgumentError)
```
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>