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 CDB7719C0021 for ; Wed, 11 Nov 2015 07:51:53 +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 133B3B5D88A for ; Wed, 11 Nov 2015 08:21:34 +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 024FD18CC7B8 for ; Wed, 11 Nov 2015 08:21:33 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6EDEA120450; Wed, 11 Nov 2015 08:21:31 +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 A1D35120400 for ; Wed, 11 Nov 2015 08:21:27 +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=YcFbAPKayf6PUuCjGqw0QTlDdZg=; b=Y9LqYZyDgmzv00+l5C mZ/Hs+L30UeN1xE3TVd9P2/XhOCCAfaAMP1R1+0qhAtwg6WnGml3bGX284scobSf WwNklKRXCJeqPItiUmDJ1pThycwK/lBGaWSWNvlDjtDwPy1IXGAVehR2DwT5xcv/ OgS8DJ2WxwymQaaL9+sVhuCDo= Received: by filter0481p1mdw1.sendgrid.net with SMTP id filter0481p1mdw1.25062.56427BF12E 2015-11-10 23:21:21.566191947 +0000 UTC Received: from herokuapp.com (ec2-54-163-138-197.compute-1.amazonaws.com [54.163.138.197]) by ismtpd0004p1iad1.sendgrid.net (SG) with ESMTP id b48yLK6DSYKDLYqDNWRdlA Tue, 10 Nov 2015 23:21:21.681 +0000 (UTC) Date: Tue, 10 Nov 2015 23:21:21 +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: 46076 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7t1dpnRZPkkzaE4dFiSEtzC/17LlL8y+c9P8 8Kp59vyC55//wzy0bhpCnGpW9DyWdO5OyRndYyIZzNDzgZZukCEcPixAuDCgeWQ1SMX5O2a/To7VTv /gSxpb71fdxhaNWIB1f+2t0eFUpJQt2SI8Ix X-ML-Name: ruby-core X-Mail-Count: 71436 Subject: [ruby-core:71436] [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. 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/