Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/Peachpie.Library.XmlDom/DOMNode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
using Pchp.Core;
Expand Down Expand Up @@ -631,11 +633,19 @@ public PhpString C14N(
PhpArray xpath = null,
PhpArray ns_prefixes = null)
{
var transform = new System.Security.Cryptography.Xml.XmlDsigC14NTransform();
transform.LoadInput(XmlNode.GetXmlDocument());
var stream = (System.IO.MemoryStream)transform.GetOutput(typeof(System.IO.Stream));
XmlNodeReader reader = new XmlNodeReader(XmlNode);
Stream inputStream = new MemoryStream();
XmlWriter writer = new XmlTextWriter(inputStream, Encoding.UTF8);

return new PhpString(stream.ToArray());
writer.WriteNode(reader, false);
writer.Flush();

inputStream.Position = 0;
XmlDsigC14NTransform transform = new XmlDsigC14NTransform();
transform.LoadInput(inputStream);

System.IO.MemoryStream outputStream = (System.IO.MemoryStream)transform.GetOutput(typeof(System.IO.Stream));
return new PhpString(outputStream.ToArray());
}

/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Peachpie.Library/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ internal static CharMap InitializeCharMap()

#endregion

// Helper function to change Console.OutputEncoding from PHP
public static void peachpie_set_string_encoding(string str) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just add a public function to the API like that. You can always define this method in privately your project, or we could add a configuration option for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't just add a public function to the API like that. You can always define this method in privately your project, or we could add a configuration option for this.

The configuration options sounds good to me.

Console.OutputEncoding = Encoding.GetEncoding(str);
}

#region ord, chr, bin2hex, hex2bin

///// <summary>
Expand Down