php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75245 simplexml_load_string() fails to parse an element filled only with spaces
Submitted: 2017-09-22 11:54 UTC Modified: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: lkppo at free dot fr Assigned:
Status: Closed Package: SimpleXML related
PHP Version: 7.0Git-2017-09-22 (Git) OS: Debian 9
Private report: No CVE-ID: None
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
13 + 25 = ?
Subscribe to this entry?

 
 [2017-09-22 11:54 UTC] lkppo at free dot fr
Description:
------------
When I parses a validating XML with simplexml_load_string(), and this XML have an element filled only with spaces, the parser find an array of string instead of a string.

Test script:
---------------
$xmlpost = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<results>
<row>
<firstname>THIERRY</firstname>
<address1>   </address1>
<address2/>
</row>
</results>
';

$xml = simplexml_load_string($xmlpost);

echo '<pre>';

var_dump($xml);

echo '</pre>';

Expected result:
----------------
object(SimpleXMLElement)#1 (1) {
  ["row"]=>
  object(SimpleXMLElement)#2 (3) {
    ["firstname"]=>
    string(7) "THIERRY"
    ["address1"]=>
    string(3) "   "
    ["address2"]=>
    object(SimpleXMLElement)#3 (0) {
    }
  }
}

Actual result:
--------------
object(SimpleXMLElement)#1 (1) {
  ["row"]=>
  object(SimpleXMLElement)#2 (3) {
    ["firstname"]=>
    string(7) "THIERRY"
    ["address1"]=>
    object(SimpleXMLElement)#3 (1) {
      [0]=>
      string(3) "   "
    }
    ["address2"]=>
    object(SimpleXMLElement)#4 (0) {
    }
  }
}

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-08-13 20:59 UTC] erik at coretech dot se
The following pull request has been associated:

Patch Name: Fix #75245: Don't set content of elements with only whitespaces
On GitHub:  https://github.com/php/php-src/pull/4533
Patch:      https://github.com/php/php-src/pull/4533.patch
 [2019-10-02 06:17 UTC] krakjoe@php.net
Automatic comment on behalf of erik@coretech.se
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6462c196897b8c5ccf606b8af8de790b77799de6
Log: Fixed #75245 Don't set content of elements with only whitespaces
 [2019-10-02 06:17 UTC] krakjoe@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 15 05:01:27 2024 UTC