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 EB8B619C0031 for ; Fri, 6 Nov 2015 05:19:27 +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 C1BC1B5D979 for ; Fri, 6 Nov 2015 05:48:28 +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 C612B18CC7EF for ; Fri, 6 Nov 2015 05:48:28 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id B824C1204D8; Fri, 6 Nov 2015 05:48:26 +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 BFA841204A6 for ; Fri, 6 Nov 2015 05:48:22 +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=SfUx6W8hU4bEDbZnzKHmsBw+Jkc=; b=rnrkdHbED4M0ee+nc3 CKHX9ZY9q1L1BpvzoRCTsIBKK5ThYVmOQhioRAKnRevPYwNcW/pmsCERspCfum8b qtveNRagDBdtcbZ42uR0UPcWAjvOhfW95jmtCsxN8jCHknt1o4QyGMi9KRs+R8Ub dpWQOcFpjYrUPNds6LE/RYE4k= Received: by filter-491.sjc1.sendgrid.net with SMTP id filter-491.1368.563BC09310 2015-11-05 20:48:19.435026602 +0000 UTC Received: from herokuapp.com (ec2-23-22-160-163.compute-1.amazonaws.com [23.22.160.163]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id qj6Z1xZwQgeIIqU2GeDNbQ for ; Thu, 05 Nov 2015 20:48:19.396 +0000 (UTC) Date: Thu, 05 Nov 2015 20:48:19 +0000 From: eddyluten@gmail.com 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: 45995 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 11661 X-Redmine-Issue-Author: eddyluten X-Redmine-Issue-Assignee: matz X-Redmine-Sender: eddyluten 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS4AnSnooYUMbu/sGulpNEvGnqMJOcKHPjyT8i e2t6WxIejUGf2gFopCyVIcKorH7zcWZ+fXzS1UsgqIn0zCYrqY7Vq9p9xWjXU/VjDXUbsbWA1vI7YL vX9Uxc8/n04shzk= X-ML-Name: ruby-core X-Mail-Count: 71354 Subject: [ruby-core:71354] [Ruby trunk - Bug #11661] [Open] 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 reported by Eddy Luten. ---------------------------------------- Bug #11661: sprintf causes a KeyError instead of using a default value for hash substitution https://bugs.ruby-lang.org/issues/11661 * Author: Eddy Luten * Status: Open * Priority: Normal * Assignee: Yukihiro Matsumoto * ruby -v: 2.3.0-dev * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- 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/