Bug 18459 - Carriage Return (\r) inserted by XElement.Load()
Summary: Carriage Return (\r) inserted by XElement.Load()
Status: RESOLVED INVALID
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.XML ()
Version: 3.0.x
Hardware: PC Linux
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-03-19 09:35 UTC by Mathias
Modified: 2014-05-23 11:12 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test program demonstrating the issue (603 bytes, text/x-csharp)
2014-03-19 09:36 UTC, Mathias
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Mathias 2014-03-19 09:35:48 UTC
If I load an XML file into an XElement object from a String(Reader) and the convert it back to a string, before every newline (\n) a carriage-return (\r) is inserted.

If you run the test program I have attached under Mono 3.2.8 (32-bit Linux) you will get the output

3C-4D-61-69-6E-3E-0A-20-20-61-0A-20-20-62-0A-3C-2F-4D-61-69-6E-3E
3C-4D-61-69-6E-3E-0D-0A-20-20-61-0D-0A-20-20-62-0D-0A-3C-2F-4D-61-69-6E-3E
3C-4D-61-69-6E-3E-0D-0A-20-20-61-0D-0A-20-20-62-0D-0A-3C-2F-4D-61-69-6E-3E

(first line is the ascii encoding of the original XML string, the other two are the output of XElement.ToString(), loaded with different options).
This shows the \r inserted in front of every newline.

This is a regression. In mono 2.10.2 (also 32-bit linux) the output is

3C-4D-61-69-6E-3E-0A-20-20-61-0A-3C-2F-4D-61-69-6E-3E
3C-4D-61-69-6E-3E-0A-20-20-61-0A-3C-2F-4D-61-69-6E-3E
3C-4D-61-69-6E-3E-0A-20-20-61-0A-3C-2F-4D-61-69-6E-3E

as should be expected.
Comment 1 Mathias 2014-03-19 09:36:18 UTC
Created attachment 6354 [details]
Test program demonstrating the issue
Comment 2 Mathias 2014-03-20 04:11:21 UTC
I'd like to add, that, evne though that may sounds like a minor issue,  if you use mono to create and verify XMLDSIG signatures it is a very critical bug.
Comment 3 Mathias 2014-03-20 05:24:11 UTC
I just found the reason for the problem. It is not in the parsing but in the String output of XElemen (as inherited by XNode). In this commit https://github.com/mono/mono/commit/7b3f562eabac201f1bd73d34e026ba358d54d6f9 the default value of NewLineHandling in XmlWriterSettings (used by XNode.ToString()) was changed from None to Replace.
Comment 4 Mathias 2014-03-20 05:29:09 UTC
According to MSDN, the new behaviour is the correct one, and it was a bug before:
http://msdn.microsoft.com/en-us/library/system.xml.xmlwritersettings.newlinehandling%28v=vs.110%29.aspx