Project

General

Profile

Bug #17011

BigDecimal .to_s should not use ASCII-8BIT

Added by david.drakard (David Drakard) 29 days ago. Updated 26 days ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux-gnu]
[ruby-core:99060]

Description

BigDecimal#to_s returns a String in ASCII-8BIT encoding. This is inconvenient in situations where the encoding determines program behaviour, since ASCII-8BIT is a special encoding that implies binary (non-textual) data, it can require an explicit conversion.

BigDecimal#to_s should either use the currently active encoding, or it should use US-ASCII like Integer#to_s.

Recreation script:

# encoding: utf-8
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
require 'bigdecimal'
puts BigDecimal('2').to_s.encoding

Desired output: US-ASCII or UTF-8

Actual output: ASCII-8BIT

#1

Updated by david.drakard (David Drakard) 29 days ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) 29 days ago

  • Description updated (diff)

Could you submit this to https://github.com/ruby/bigdecimal?

Updated by byroot (Jean Boussier) 29 days ago

Actually, it's already been fixed upstream: https://github.com/ruby/bigdecimal/pull/160

Maybe the Ruby spec part of my PR is still useful. I'll submit it to https://github.com/ruby/spec

Updated by Eregon (Benoit Daloze) 29 days ago

How should we proceed to include that fix in CRuby master?

Updated by Eregon (Benoit Daloze) 26 days ago

  • Assignee set to nobu (Nobuyoshi Nakada)
  • Status changed from Open to Closed

Also available in: Atom PDF