Project

General

Profile

Actions

Bug #17011

closed

BigDecimal .to_s should not use ASCII-8BIT

Added by david.drakard (David Drakard) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
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

Actions #1

Updated by david.drakard (David Drakard) almost 4 years ago

  • Description updated (diff)

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Description updated (diff)

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

Updated by byroot (Jean Boussier) almost 4 years 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) almost 4 years ago

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0