[ruby-core:109430] [Ruby master Bug#18957] StringIO#printf doesn't ignore initial String value
From:
"andrykonchin (Andrew Konchin)" <noreply@...>
Date:
2022-08-06 11:49:21 UTC
List:
ruby-core #109430
Issue #18957 has been reported by andrykonchin (Andrew Konchin).
----------------------------------------
Bug #18957: StringIO#printf doesn't ignore initial String value
https://bugs.ruby-lang.org/issues/18957
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* ruby -v: 3.0.3
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
I've noticed that `StringIO#printf` diverges from `IO#printf` in the following way:
IO:
```ruby
File.write("printf.txt", "1234567890")
f = File.open("printf.txt", "w+")
f.printf("%s", "abc")
f.rewind
f.gets
# => "abc"
```
StringIO:
```ruby
io = StringIO.new("1234567890")
io.printf("%s", "abc")
io.rewind
io.gets
=> "abc4567890"
```
So `File` opened in a `w` mode "truncates" existing file content but `StirngIO` (by default) doesn't.
I would expect `StringIO` behaves in the same way.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>