Taritsyn / WebMarkupMin

The Web Markup Minifier (abbreviated WebMarkupMin) - a .NET library that contains a set of markup minifiers. The objective of this project is to improve the performance of web applications by reducing the size of HTML, XHTML and XML code.
Apache License 2.0
440 stars 48 forks source link

XML minification #164

Closed LuckyTil closed 11 months ago

LuckyTil commented 11 months ago

.AddXmlMinification( options => { options.MinificationSettings.CollapseTagsWithoutContent = true; } )

When process to download XML with encoding "windows-1251", tags (maybe attributes too) with Cyrillic content become corrupt.

Example

Corrupted value: `

пїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅ2

`

Correct value: `

Пункт тестування ДЗЮ2

`

Taritsyn commented 11 months ago

Hello, Ihor!

  1. Which WebMarkupMin ASP.NET extension are you using?
  2. Is this XML code generated programmatically or is it a static file?
LuckyTil commented 11 months ago
  1. Which WebMarkupMin ASP.NET extension are you using?

WebMarkupMin.AspNetCore5 2.14.1

  1. Is this XML code generated programmatically or is it a static file?

XML generated programmatically and returned due ControllerBase.File method, stream overload, content type "text/xml"

Taritsyn commented 11 months ago

XML generated programmatically and returned due ControllerBase.File method, stream overload, content type "text/xml"

This extension determines the text encoding based on the ContentType property of response. Try replacing the text/xml content type by the text/xml; charset=windows-1251.

LuckyTil commented 11 months ago

This extension determines the text encoding based on the ContentType property of response. Try replacing the text/xml content type by the text/xml; charset=windows-1251.

Why did XML header not used to determine encoding?

<?xml version="1.0" encoding="windows-1251"?>
Taritsyn commented 11 months ago

Why did XML header not used to determine encoding?

Because text content is read from the response and at the time of reading, data is available only as an array of bytes. To convert an array of bytes to text, we need to know the encoding.

LuckyTil commented 11 months ago

Thank You, @Taritsyn