Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update Library.XmlDom.XMLWriter /peachpie/issues/1142 #1140

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
[<img align="right" src="https://github.com/peachpiecompiler/peachpie/blob/master/docs/logos/dotnet-foundation-logo.png" width="100" />](https://www.dotnetfoundation.org/)
PeachPie is a member project of the [.NET Foundation](https://www.dotnetfoundation.org/about).

## 本分支是为修复汉字的兼容性
> This branch is to fix the compatibility of Chinese characters

## Continuous Integration

| Service | Platform | Build Status |
Expand Down
2 changes: 1 addition & 1 deletion build/build.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Param(
[string]$version = "1.0.0-dev",
[string]$version = "1.2.0-dev",
[string]$config = "Debug"
)

Expand Down
2 changes: 1 addition & 1 deletion build/dummy/dummy.msbuildproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Peachpie.NET.Sdk/1.0.0-dev">
<Project Sdk="Peachpie.NET.Sdk/1.2.0-dev">

<PropertyGroup>
<TargetFramework>net50</TargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion build/update-cache.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Note: In prior to use Powershell scripts, it might be needed to run:
# powershell Set-ExecutionPolicy Unrestricted -Scope CurrentUser

param([string]$version = "1.0.0", [string]$suffix = "dev")
param([string]$version = "1.2.0", [string]$suffix = "dev")

# We suppose the global package source is in the default location
$rootDir = [System.IO.Path]::GetFullPath("$PSScriptRoot/..")
Expand Down
54 changes: 32 additions & 22 deletions src/Peachpie.Library.XmlDom/XmlWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ namespace Peachpie.Library.XmlDom
[PhpType(PhpTypeAttribute.InheritName), PhpExtension("xmlwriter")]
public class XMLWriter : IDisposable
{

#region Constants

private protected const string DefaultXmlVersion = "1.0";

#endregion

#region Fields and properties
XmlTextWriter _writer;

System.Xml.XmlWriter _writer;
//wjw - System.Xml.XmlWriter _writer;
MemoryStream _memoryStream;
PhpStream _uriPhpStream;

Expand Down Expand Up @@ -212,7 +214,7 @@ public bool endDtd()
_state.Pop();

// Closes dtd section.
string end = _writer.Settings.Indent ? _writer.Settings.NewLineChars : "";
string end = _writer.Formatting == Formatting.Indented ? DefaultSettings.NewLineChars : ""; // string end = _writer.Settings.Indent ? _writer.Settings.NewLineChars : "";
end += _dtdStart ? ">" : "]>";
_dtdStart = false;

Expand Down Expand Up @@ -292,7 +294,9 @@ public bool openMemory(Context ctx)
{
Clear();
_memoryStream = new MemoryStream();
_writer = System.Xml.XmlWriter.Create(_memoryStream, DefaultSettings);
_writer = new XmlTextWriter(_memoryStream, DefaultSettings.Encoding); //_writer = System.Xml.XmlWriter.Create(_memoryStream, DefaultSettings);
_writer.Formatting = DefaultSettings.Indent ? Formatting.Indented : Formatting.None;

ctx.RegisterDisposable(this);
return true;
}
Expand All @@ -309,7 +313,7 @@ public bool openUri(Context ctx, string uri)

try
{
_writer = System.Xml.XmlWriter.Create(_uriPhpStream.RawStream, DefaultSettings);
_writer = new XmlTextWriter(_uriPhpStream.RawStream, DefaultSettings.Encoding); //_writer = System.Xml.XmlWriter.Create(_uriPhpStream.RawStream, DefaultSettings);
ctx.RegisterDisposable(this);
return true;
}
Expand Down Expand Up @@ -340,13 +344,13 @@ public bool setIndentString(string indentString)
return false;

// The settings is read-only, but we can create a new xmlwriter if the current xmlwriter haven't written anything yet.
var settings = _writer.Settings.Clone();
var settings =DefaultSettings.Clone(); // var settings = _writer.Settings.Clone();
settings.IndentChars = indentString;

if (_uriPhpStream == null)
_writer = XmlWriter.Create(_memoryStream, settings);
_writer = new XmlTextWriter(_memoryStream, settings.Encoding); //_writer = XmlWriter.Create(_memoryStream, settings);
else
_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);
_writer = new XmlTextWriter(_uriPhpStream.RawStream, settings.Encoding); //_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);

return true;
}
Expand All @@ -357,13 +361,13 @@ public bool setIndent(bool indent)
return false;

// The settings is read-only, but we can create a new xmlwriter if the current xmlwriter haven't written anything yet.
var settings = _writer.Settings.Clone();
var settings = DefaultSettings.Clone(); // var settings = _writer.Settings.Clone();
settings.Indent = indent;

if (_uriPhpStream == null)
_writer = XmlWriter.Create(_memoryStream, settings);
_writer = new XmlTextWriter(_memoryStream, settings.Encoding); //_writer = XmlWriter.Create(_memoryStream, settings);
else
_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);
_writer = new XmlTextWriter(_uriPhpStream.RawStream, settings.Encoding); //_writer = XmlWriter.Create(_uriPhpStream.RawStream, settings);

return true;
}
Expand Down Expand Up @@ -422,16 +426,16 @@ public bool startDocument(string version = DefaultXmlVersion, string encoding =
if (string.IsNullOrEmpty(standalone))
{
bool res = CheckedCall(() => _writer.WriteStartDocument());
if (!_writer.Settings.Indent) // Php writes a new line character after prolog.
res &= CheckedCall(() => _writer.WriteRaw(_writer.Settings.NewLineChars));
if (_writer.Formatting==Formatting.None) // if (!_writer.Settings.Indent) // Php writes a new line character after prolog.
res &= CheckedCall(() => _writer.WriteRaw(DefaultSettings.NewLineChars)); //res &= CheckedCall(() => _writer.WriteRaw(_writer.Settings.NewLineChars));

return res;
}
else
{
bool res = CheckedCall(() => _writer.WriteStartDocument(standalone == "yes"));
if (!_writer.Settings.Indent) // Php writes a new line character after prolog.
res &= CheckedCall(() => _writer.WriteRaw(_writer.Settings.NewLineChars));
if (_writer.Formatting == Formatting.None) // if (!_writer.Settings.Indent) // Php writes a new line character after prolog.
res &= CheckedCall(() => _writer.WriteRaw(DefaultSettings.NewLineChars)); // res &= CheckedCall(() => _writer.WriteRaw(_writer.Settings.NewLineChars));

return res;
}
Expand Down Expand Up @@ -476,7 +480,8 @@ public bool startDtdEntity(string name, bool isparam)
public bool startDtd(string qualifiedName, string publicId = null, string systemId = null)
{
if (_state.Count != 0 || // DTD can be only placed in default section and prolog.
(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
//(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
(DefaultSettings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
{
PhpException.Throw(PhpError.Warning, Resources.XmlWritterDtdInProlog);
return false;
Expand All @@ -491,9 +496,11 @@ public bool startDtd(string qualifiedName, string publicId = null, string system
// Makes a doctype
string doctype = $"<!DOCTYPE {qualifiedName}";
if (!String.IsNullOrEmpty(publicId))
doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
//doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
doctype += _writer.Formatting==Formatting.Indented ? $"{DefaultSettings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
if (!String.IsNullOrEmpty(systemId))
doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}SYSTEM \"{systemId}\"" : $" SYSTEM \"{systemId}\"";
//doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}SYSTEM \"{systemId}\"" : $" SYSTEM \"{systemId}\"";
doctype += _writer.Formatting == Formatting.Indented ? $"{DefaultSettings.NewLineChars}SYSTEM \"{systemId}\"" : $" SYSTEM \"{systemId}\"";

CheckDtdStartHelper();
_state.Push(State.DTD);
Expand Down Expand Up @@ -662,7 +669,8 @@ public bool writeDtdEntity(string name, string content, bool pe = false)
public bool writeDtd(string name, string publicId = null, string systemId = null, string subset = null)
{
if (_state.Count != 0 ||
(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
//(_writer.Settings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
(DefaultSettings.ConformanceLevel == ConformanceLevel.Document && _writer.WriteState != WriteState.Prolog && _writer.WriteState != WriteState.Start))
{
PhpException.Throw(PhpError.Warning, Resources.XmlWritterDtdInProlog);
return false;
Expand All @@ -677,9 +685,11 @@ public bool writeDtd(string name, string publicId = null, string systemId = null
// Makes doctype
string doctype = $"<!DOCTYPE {name}";
if (!String.IsNullOrEmpty(publicId))
doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
//doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
doctype += _writer.Formatting==Formatting.Indented ? $"{DefaultSettings.NewLineChars}PUBLIC \"{publicId}\"" : $" PUBLIC \"{publicId}\"";
if (!String.IsNullOrEmpty(systemId))
doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars} \"{systemId}\"" : $" \"{systemId}\"";
//doctype += _writer.Settings.Indent ? $"{_writer.Settings.NewLineChars} \"{systemId}\"" : $" \"{systemId}\"";
doctype += _writer.Formatting == Formatting.Indented ? $"{DefaultSettings.NewLineChars} \"{systemId}\"" : $" \"{systemId}\"";
if (!String.IsNullOrEmpty(subset))
doctype += $" [{subset}]";
doctype += ">";
Expand Down Expand Up @@ -740,9 +750,9 @@ private void CheckDtdStartHelper()
_dtdStart = false;
}

if (_writer.Settings.Indent)
if (_writer.Formatting==Formatting.Indented) //if (_writer.Settings.Indent)
{
_writer.WriteRaw(_writer.Settings.NewLineChars);
_writer.WriteRaw(DefaultSettings.NewLineChars); //_writer.WriteRaw(_writer.Settings.NewLineChars);

if (_state.Count != 0 && _state.Peek() == State.DTD)
_writer.WriteRaw(" ");
Expand Down
14 changes: 14 additions & 0 deletions src/Peachpie.Library/iconv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ namespace Pchp.Library
[PhpExtension("iconv", Registrator = typeof(PhpIconv.Registrator))]
public static class PhpIconv
{
/// <summary>
/// wjw add 2024-04-08 增加一个静态构造,汉字编码支持 18行
/// </summary>
static PhpIconv()
{
try
{
Encoding.GetEncoding("GBK");
}
catch (Exception)
{
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
}
}
#region IconvConfig, Options

sealed class IconvConfig : IPhpConfiguration
Expand Down
2 changes: 1 addition & 1 deletion src/Peachpie.NET.Sdk/Peachpie.NET.Sdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<AssemblyName>Peachpie.NET.Sdk</AssemblyName>

<Version Condition=" '$(Version)'=='' ">1.0.0-dev</Version>
<Version Condition=" '$(Version)'=='' ">1.2.0-dev</Version>
<PackageOnlyBuild>true</PackageOnlyBuild>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
Expand Down