msg182320 - (view) |
Author: Ferdinand Beyer (fbeyer) |
Date: 2013-02-18 13:19 |
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 |
|
|
msg182329 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-02-18 17:05 |
Here is a patch. This change breaks tests, but unlikely anything except tests depends on exact error message. |
|
|
msg182578 - (view) |
Author: Ezio Melotti (ezio.melotti) *  |
Date: 2013-02-21 02:54 |
Are these values accessible from somewhere (e.g. as attributes of the exception)? |
|
|
msg182583 - (view) |
Author: Ferdinand Beyer (fbeyer) |
Date: 2013-02-21 10:19 |
Line and column number are included in the formatted error message ("raise ValueError(errormsg(...))"). They are currently not accessible separately as exception arguments. |
|
|
msg182589 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-02-21 12:05 |
These values used only in the exception message. However current (3.0.8, stdlib json based on 2.0.9) simplejson exposes them as an exception attributes. http://simplejson.readthedocs.org/en/latest/#exceptions |
|
|
msg182603 - (view) |
Author: Bob Ippolito (bob.ippolito) *  |
Date: 2013-02-21 17:50 |
I've applied a very similar patch to simplejson and released 3.0.9 https://github.com/simplejson/simplejson/commit/44d7709a31f3a19f3d465411585ebb7be7fa2295 |
|
|
msg182604 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-02-21 17:52 |
https://github.com/simplejson/simplejson/issues/57 Simplejson has fixed this for about 6 hours. |
|
|
msg182605 - (view) |
Author: Roundup Robot (python-dev)  |
Date: 2013-02-21 18:31 |
New changeset ce583eb0bec2 by Serhiy Storchaka in branch '2.7': Issue #17225: JSON decoder now counts columns in the first line starting http://hg.python.org/cpython/rev/ce583eb0bec2 New changeset 36220cf535aa by Serhiy Storchaka in branch '3.2': Issue #17225: JSON decoder now counts columns in the first line starting http://hg.python.org/cpython/rev/36220cf535aa New changeset 361ba6d4b7c9 by Serhiy Storchaka in branch '3.3': Issue #17225: JSON decoder now counts columns in the first line starting http://hg.python.org/cpython/rev/361ba6d4b7c9 New changeset 69f793cc34fc by Serhiy Storchaka in branch 'default': Issue #17225: JSON decoder now counts columns in the first line starting http://hg.python.org/cpython/rev/69f793cc34fc |
|
|
msg182606 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2013-02-21 18:56 |
Thank you for the report, Ferdinand. |
|
|