From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: poffice@blade.nagaokaut.ac.jp Delivered-To: poffice@blade.nagaokaut.ac.jp Received: from kankan.nagaokaut.ac.jp (kankan.nagaokaut.ac.jp [133.44.2.24]) by blade.nagaokaut.ac.jp (Postfix) with ESMTP id 370DD19C0061 for ; Tue, 10 Nov 2015 20:07:40 +0900 (JST) Received: from voscc.nagaokaut.ac.jp (voscc.nagaokaut.ac.jp [133.44.1.100]) by kankan.nagaokaut.ac.jp (Postfix) with ESMTP id 97A2BB5D8FB for ; Tue, 10 Nov 2015 20:37:15 +0900 (JST) Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by voscc.nagaokaut.ac.jp (Postfix) with ESMTP id EB3C218CC7AF for ; Tue, 10 Nov 2015 20:37:15 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id CC20D120481; Tue, 10 Nov 2015 20:37:13 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o10.shared.sendgrid.net (o10.shared.sendgrid.net [173.193.132.135]) by neon.ruby-lang.org (Postfix) with ESMTPS id A2BB8120457 for ; Tue, 10 Nov 2015 20:37:09 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=gIgYUjBaZyA4vjYQoTNkzgJL+08=; b=L5iMK7nl6U8cM5/7Bv 2dinQ7JtFM6Jet2jovdNljGaCThVj45mSwJENkiU3ycqkaQ8VM7vd/Cb9j4CFnZh tqkC5Hl1mwM3R5QaMOo5M0THQzdWa4KAF5yo1/uimOrS5O0K6GXQasl+Tn0KVgyy /PZlBEFXdoWgQMROdHTeX/cTQ= Received: by filter-294.sjc1.sendgrid.net with SMTP id filter-294.21382.5641D6DF35 2015-11-10 11:37:03.405041648 +0000 UTC Received: from herokuapp.com (ec2-54-162-152-238.compute-1.amazonaws.com [54.162.152.238]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id wdLDa_51RHqSnwkWzm8vbw for ; Tue, 10 Nov 2015 11:37:03.665 +0000 (UTC) Date: Tue, 10 Nov 2015 11:37:03 +0000 From: nobu@ruby-lang.org To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Redmine-MailingListIntegration-Message-Ids: 46070 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11661 X-Redmine-Issue-Author: eddyluten X-Redmine-Issue-Assignee: matz X-Redmine-Sender: nobu X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS5Vjy3T3x+Mw8Q5NBaWSts9O9L8p1iXDIq0Fc aMETrDHM+Lv1dds6/rud179NMJHG56S8/A8gdlRanxBRLgQvEug37GE7jsLx0RgvWLaINAmtUfePs8 LFi9ECVGaAJYQOo= X-ML-Name: ruby-core X-Mail-Count: 71430 Subject: [ruby-core:71430] [Ruby trunk - Bug #11661] sprintf causes a KeyError instead of using a default value for hash substitution X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #11661 has been updated by Nobuyoshi Nakada. Tracker changed from Feature to Bug Backport set to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED ---------------------------------------- Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution https://bugs.ruby-lang.org/issues/11661#change-54800 * 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/