ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: nobu@ruby-lang.org
To: ruby-core@ruby-lang.org
Subject: [ruby-core:71436] [Ruby trunk - Bug #11661] sprintf causes a KeyError instead of using a default value for hash substitution
Date: Tue, 10 Nov 2015 23:21:21 +0000	[thread overview]
Message-ID: <redmine.journal-54805.20151110232120.3178e5a0edc23224@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-11661.20151105204817@ruby-lang.org

Issue #11661 has been updated by Nobuyoshi Nakada.


Unfortunately, this change conflict with rubyspec.
How should we do:

1. backport the fix and remove the failed spec
2. add version guard and fix only the trunk
3. keep the current behavior

----------------------------------------
Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution
https://bugs.ruby-lang.org/issues/11661#change-54805

* 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/

      parent reply	other threads:[~2015-11-10 22:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-11661.20151105204817@ruby-lang.org>
2015-11-05 20:48 ` [ruby-core:71354] [Ruby trunk - Bug #11661] [Open] sprintf causes a KeyError instead of using a default value for hash substitution eddyluten
2015-11-08  7:58 ` [ruby-core:71386] [Ruby trunk - Feature #11661] [Feedback] " nobu
2015-11-08  8:36 ` [ruby-core:71387] [Ruby trunk - Feature #11661] [Assigned] " nobu
2015-11-10 11:37 ` [ruby-core:71430] [Ruby trunk - Bug #11661] " nobu
2015-11-10 12:34 ` [ruby-core:71431] " hanmac
2015-11-10 19:57 ` [ruby-core:71434] " eddyluten
2015-11-10 23:21 ` nobu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-54805.20151110232120.3178e5a0edc23224@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).