samdark/sitemap

A special char (
) is inserted in the sitemap.xml output

Closed this issue · 8 comments

Hello,

I installed the package with composer (composer require samdark/sitemap) so I'm running version 2.2.0. My environment is Windows 7, PHP 7.2.13.

Here's the code I tested:

use samdark\sitemap\Sitemap;

$sitemap = new Sitemap(__DIR__ . '/sitemap.xml');
$sitemap->addItem('http://example.com/mylink1');
$sitemap->write();

And this is the output I get:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">&#13;
 <url>
  <loc>http://example.com/mylink1</loc>
 </url>
</urlset>

I think the &#13; is a bug... or did I miss something?

Yes, it does not look right.

I also see this problem. I skimmed through the code, but I do not understand what causes this situation.

I found a bug. Using the PHP_EOL constant under Windows gives an extra byte of "\r". It is necessary to replace the constant PHP_EOL with "\n". Sorry for bad english.

@PhantomArt you mean it's in the source code?

@samdark, file Sitemap.php, line 173:

$this->writer->text(PHP_EOL);

I propose to replace with:

$this->writer->text("\n");

This solves the problem.

Ah! That thing. Yes. That should be it. Do you want to do a pull request?

I am ashamed to admit that I have never used GIT. Could you make this change yourself?

Sure.