icamys / php-sitemap-generator

A simple PHP sitemap generator.
MIT License
168 stars 65 forks source link

Remove function call htmlspecialchars from XMLWriter #42

Closed jwv closed 1 year ago

jwv commented 2 years ago

Hi,

The function htmlspecialchars($loc, ENT_QUOTES) no need be call because xmlWriter already convert special characters and was small bug with & (ampersand ).

For example when add URL with & was convert to &

Examples: https://example.com/index.php?param1=1&param2=2&param3=3 => https://example.com/index.php?param1=1&param2=2&param3=3

image image image

icamys commented 1 year ago

Hi @jwv and thank you for the proposal! It made me review the entire process of escaping and encoding the URLs.

The function htmlspecialchars($url, ENT_QUOTES) is used for converting single and double quotes to HTML entities - this is a requirement of the sitemap specification. So the function will stay definitely there. If you take a look at the spec, you'll notice that it requires not only to escape ampersands, quotes, and greater than/less than signs but also encode non-ASCII characters to UTF-8. The latter feature was not in place and I added it in #51.