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: -
From: lkppo at free dot fr Assigned:
Status: Open Package: SimpleXML related
PHP Version: 7.0Git-2017-09-22 (Git) OS: Debian 9
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 23:01:25 2019 UTC