[#71439] [Ruby trunk - Feature #11339] [PATCH] io.c: avoid kwarg parsing in C API — matz@...
Issue #11339 has been updated by Yukihiro Matsumoto.
7 messages
2015/11/11
[#71473] Re: [Ruby trunk - Feature #11339] [PATCH] io.c: avoid kwarg parsing in C API
— Eric Wong <normalperson@...>
2015/11/13
Entire series for sockets
[#71450] Ruby 2.3.0-preview1 Released — "NARUSE, Yui" <naruse@...>
Hi,
5 messages
2015/11/11
[#71617] [Ruby trunk - Feature #11664] [PATCH] introduce rb_autoload_value to replace rb_autoload — nobu@...
Issue #11664 has been updated by Nobuyoshi Nakada.
3 messages
2015/11/20
[#71721] [Ruby trunk - Feature #11741] Migrate Ruby to Git from Subversion — me@...
Issue #11741 has been updated by Jon Moss.
4 messages
2015/11/28
[ruby-core:71434] [Ruby trunk - Bug #11661] sprintf causes a KeyError instead of using a default value for hash substitution
From:
eddyluten@...
Date:
2015-11-10 19:57:00 UTC
List:
ruby-core #71434
Issue #11661 has been updated by Eddy Luten.
Hans Mackowiak wrote:
> hm might it be possible that sprintf only uses default value/or default proc if the hash does has default,
> but does still raise KeyError if it doesnt?
>
> another idea would be that is does try to use hash[key] function if hash is a non-hash object.
> (but that might reduce the calcing speed if not checked right)
Nobuyoshi Nakada: this was the change I initially made myself but couldn't get it to work properly with hash substitutions. Maybe I did something wrong in my testing, I will attempt to use your changes, thanks! :)
Hans Mackowiak: so raise KeyError is the default is `nil`? I think that could work, since if you wanted empty strings as a default, you could simply set an empty string as default value. However, logically, since `"#{nil}" (and `nil.to_s` for that case) works and returns an empty string, the modulus operator version of it should work the same. What do you think?
Also a general question, how would I go about making the Rubyspec tests pass for this particular pull request? Do I open another PR for the tests in Rubyspec? If so, how do I link these two PRs to work together in the Travis CI build acceptance test?
----------------------------------------
Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution
https://bugs.ruby-lang.org/issues/11661#change-54803
* Author: Eddy Luten
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
* ruby -v:
* Backport: 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
----------------------------------------
When using a format string that substitutes hash values (or using the `%` operator on a string), instead of using the Hash's default value if a key is not present, it causes a KeyError.
As an end-user, to get around this, my hash needs to know about all the possible keys ahead of time and pre-assign a value to them or handle the KeyError. Logically, I would assume that the `sprintf` implementation would use the default Hash value.
I wanted to open this issue to see what your collective thoughts were on this since I have a fork running locally that fixes this issue and was wondering if I could send a patch/PR for this.
This issue is reproducible using the following code:
```ruby
my_hash = Hash.new('world')
puts "hello %{location}" % my_hash # expecting "hello world"
# "KeyError: key{location} not found"
```
--
https://bugs.ruby-lang.org/