sitemap icon indicating copy to clipboard operation
sitemap copied to clipboard

Sometime a sitemap contains more than $maxUrls URLs

Open DarkSilence opened this issue 3 years ago • 2 comments

The problem lays in flush() function.

When a sitemap is truncated by size here:

https://github.com/samdark/sitemap/blob/a7ba091766afeb5fad1ea3056b30f26c3a620962/Sitemap.php#L232

finishFile() functions is called which leads to zeroing urlsCount variable, but right after that a remaining chunk is appended to a file here (with contains up to $bufferSize URLs):

https://github.com/samdark/sitemap/blob/a7ba091766afeb5fad1ea3056b30f26c3a620962/Sitemap.php#L240

Those URLs in that chunk aren't counted anywhere and a next sitemap overflows.

DarkSilence avatar Jan 10 '22 06:01 DarkSilence

Here's a sample which reproduces the problem: https://gist.github.com/DarkSilence/9c2bca943d639aae3ad995d8cf35de60

sitemap_test_4.xml should contain 100 records, but it contains 110 records.

DarkSilence avatar Jan 10 '22 09:01 DarkSilence

@DarkSilence would you please convert that sample into unit test? That way we'll be sure it won't be broken again ever.

samdark avatar Jan 10 '22 12:01 samdark