[issue1780] Decimal constructor accepts newline terminated strings

Mark Dickinson report at bugs.python.org
Thu Jan 10 02:01:46 CET 2008


New submission from Mark Dickinson:

After seeing issue #1761, I realized that there's a bug in the Decimal 
constructor:  it accepts newline-terminated strings:

>>> from decimal import *
>>> s = "2.3\n"
>>> Decimal(s)
Decimal("2.3")

I think this is, strictly speaking, a bug because:

(1) The IBM decimal specification explicitly disallows additional whitespace 
in a numeric string (see http://www2.hursley.ibm.com/decimal/daconvs.html),

(2) the operation to-number is supposed only to accept numeric strings, and

(3) Decimal.__new__ is currently the method that implements to-number.

Is this worth fixing?  This buggy behaviour might well be useful (e.g. to 
someone parsing a file with one Decimal per line).

I'll fix it if anyone thinks it's worth it.  Even if it should be fixed, I 
don't think this is worth backporting to Python 2.5, especially since it 
might break things.

----------
assignee: facundobatista
components: Library (Lib)
messages: 59642
nosy: facundobatista, marketdickinson
priority: normal
severity: minor
status: open
title: Decimal constructor accepts newline terminated strings
type: behavior
versions: Python 2.5, Python 2.6, Python 3.0

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1780>
__________________________________


More information about the Python-bugs-list mailing list