php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44741 dom mangles returns (\r)
Submitted: 2008-04-16 10:41 UTC Modified: 2008-04-16 12:16 UTC
From: php at benjaminschulz dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3CVS-2008-04-16 (CVS) OS: linux, osx, windows
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: php at benjaminschulz dot com
New email:
PHP Version: OS:

 

 [2008-04-16 10:41 UTC] php at benjaminschulz dot com
Description:
------------
If you load a xml document that contains \r they are silently replaced by \n, even in CDATAs.
No matter to what ignoreWhiteSpace is set.

Reproduce code:
---------------
<?php
$doc = new DomDocument;
$xml = "<?xml version=\"1.0\"?><foo>\r \r\n <![CDATA[\r]]></foo>";
$doc->loadXml($xml);
var_dump(substr_count($doc->saveXml(), "\r"));
var_dump(substr_count($doc->saveXml(), "\n"));

Expected result:
----------------
int(3) int(1) 

This is the output of:
var_dump(substr_count($xml, "\r"));
var_dump(substr_count($xml, "\n"));

Actual result:
--------------
int(0) int(5) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-16 12:01 UTC] php at benjaminschulz dot com
this is reproducable on linux, osx and windows
 [2008-04-16 12:16 UTC] rrichards@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

In XML, no matter what parser you use, carriage returns are removed or 
replaced with a line feed in documents before processing them. You must 
use character entities to preserve a carriage return.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 05:01:28 2024 UTC