[New-bugs-announce] [issue17225] JSON decoder reports wrong column number on first line

Ferdinand Beyer report at bugs.python.org
Mon Feb 18 14:19:26 CET 2013


New submission from Ferdinand Beyer:

The linecol() function in json/decoder.py computes the line and column numbers for a byte offset in a string.  Both numbers are expected to start with 1 (as in text editors).

If the position is in the first line, the returned column is off by one (or starting with zero):

    >>> from json.decoder import linecol
    >>> linecol('spam', 0)  # Should be (1, 1)
    (1, 0)
    >>> linecol('\nspam', 1)
    (2, 1)

The problem is the line:

    if lineno == 1:
        colno = pos

that should read

    if lineno == 1:
        colno = pos + 1

----------
components: Library (Lib)
messages: 182320
nosy: fbeyer
priority: normal
severity: normal
status: open
title: JSON decoder reports wrong column number on first line
type: behavior
versions: Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17225>
_______________________________________


More information about the New-bugs-announce mailing list