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 D199519C0059 for ; Sun, 8 Nov 2015 17:07:07 +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 F2542B5D8C9 for ; Sun, 8 Nov 2015 17:36:26 +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 30D2E18CC7B2 for ; Sun, 8 Nov 2015 17:36:26 +0900 (JST) Received: from [221.186.184.76] (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 2A69B12046B; Sun, 8 Nov 2015 17:36:25 +0900 (JST) X-Original-To: ruby-core@ruby-lang.org Delivered-To: ruby-core@ruby-lang.org Received: from o2.heroku.sendgrid.net (o2.heroku.sendgrid.net [67.228.50.55]) by neon.ruby-lang.org (Postfix) with ESMTPS id E838112045C for ; Sun, 8 Nov 2015 17:36:20 +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=SZKm24iQytHUIfh6w//f2aN5I4M=; b=M65BaxNJa4P7D4v0V0 nNaJVhYx9Ta5t71rFAJi+Cyuh5YTz5AnMpLPi0s7IC4gMCLIsVXApx3ZZ7dOrVcf b60RfwZvHPxLHkREAONDcuvH9mN5yoRBvmmfPIpVs4EQvSxvZVu+PAldI7Fev2yf e1C4CbE5kQFIpLJopYRhod08c= Received: by filter-486.sjc1.sendgrid.net with SMTP id filter-486.1791.563F09818 2015-11-08 08:36:17.129463965 +0000 UTC Received: from herokuapp.com (ec2-54-163-168-119.compute-1.amazonaws.com [54.163.168.119]) by ismtpd0001p1iad1.sendgrid.net (SG) with ESMTP id MSjGaHNER0SsDZjwTRemaA for ; Sun, 08 Nov 2015 08:36:16.994 +0000 (UTC) Date: Sun, 08 Nov 2015 08:36:16 +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: 46030 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/Ymy4QrNMhiuLXJG8OTL2vJD1yS7kU6NJ3fMtFiDR5hfO/w0zTWWaTbrhdoT6EZ 5eb+veGsdZrufs6NRcINihBo24J9gBtcXutrmpIAG+BkRQSm+HawjfovYNB8FcU9w/ISYnJVU9zYMi cnS9/VXE/oFkW3g= X-SendGrid-Contentd-ID: {"test_id":"1446971778"} X-ML-Name: ruby-core X-Mail-Count: 71387 Subject: [ruby-core:71387] [Ruby trunk - Feature #11661] [Assigned] 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. Status changed from Feedback to Assigned ---------------------------------------- Feature #11661: sprintf causes a KeyError instead of using a default value for hash substitution https://bugs.ruby-lang.org/issues/11661#change-54758 * Author: Eddy Luten * Status: Assigned * Priority: Normal * Assignee: Yukihiro Matsumoto ---------------------------------------- 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/