php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80678 json_decode fails on numbers with explizit "+" sign
Submitted: 2021-01-28 10:40 UTC Modified: 2021-01-28 10:44 UTC
From: rainer-phpbugs at 7val dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 8.0.1 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rainer-phpbugs at 7val dot com
New email:
PHP Version: OS:

 

 [2021-01-28 10:40 UTC] rainer-phpbugs at 7val dot com
Description:
------------
The JSON standard allows positive numbers to be represented with an explicit "+" sign, e.g. +123 (see the "sign" production on https://www.json.org/json-en.html). json_decode() fails and returns NULL for any JSON string that contains such a number.

Also affects 7.3 and 7.4 branches.

Test script:
---------------
<?php

$x=json_decode('+123.4');
var_export($x);
print("\n");

$x=json_decode('123.4');
var_export($x);
print("\n");


Expected result:
----------------
123.4
123.4


Actual result:
--------------
NULL
123.4

Patches

json_decode_positive_sign.patch (last revision 2021-01-28 10:42 UTC by phpbugs at canavan dot de)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-01-28 10:42 UTC] phpbugs at canavan dot de
The following patch has been added/updated:

Patch Name: json_decode_positive_sign.patch
Revision:   1611830541
URL:        https://bugs.php.net/patch-display.php?bug=80678&patch=json_decode_positive_sign.patch&revision=1611830541
 [2021-01-28 10:44 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2021-01-28 10:44 UTC] nikic@php.net
A + sign is only allowed as part of a floating-point exponent, such as 1.0e+1. Just +1 in isolation is malformed JSON.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Wed Dec 07 16:05:57 2022 UTC