diff --git a/projects/plugins/jetpack/changelog/add-line-breaks-sitemap b/projects/plugins/jetpack/changelog/add-line-breaks-sitemap
new file mode 100644
index 0000000000000..6f1e8e76e275e
--- /dev/null
+++ b/projects/plugins/jetpack/changelog/add-line-breaks-sitemap
@@ -0,0 +1,4 @@
+Significance: patch
+Type: bugfix
+
+Sitemaps: include line breaks for easier debugging
diff --git a/projects/plugins/jetpack/modules/sitemaps/sitemap-buffer.php b/projects/plugins/jetpack/modules/sitemaps/sitemap-buffer.php
index b2aac925fd3a6..f61781955c087 100644
--- a/projects/plugins/jetpack/modules/sitemaps/sitemap-buffer.php
+++ b/projects/plugins/jetpack/modules/sitemaps/sitemap-buffer.php
@@ -110,8 +110,10 @@ public function __construct( $item_limit, $byte_limit, $time ) {
$this->is_full_flag = false;
$this->timestamp = $time;
- $this->finder = new Jetpack_Sitemap_Finder();
- $this->doc = new DOMDocument( '1.0', 'UTF-8' );
+ $this->finder = new Jetpack_Sitemap_Finder();
+ $this->doc = new DOMDocument( '1.0', 'UTF-8' );
+ $this->doc->formatOutput = true;
+ $this->doc->preserveWhiteSpace = false;
$this->item_capacity = max( 1, (int) $item_limit );
$this->byte_capacity = max( 1, (int) $byte_limit ) - strlen( $this->doc->saveXML() );
diff --git a/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-buffer.php b/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-buffer.php
index 27a52aacc6142..75d6b4b30498c 100644
--- a/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-buffer.php
+++ b/projects/plugins/jetpack/tests/php/modules/sitemaps/test-class.sitemap-buffer.php
@@ -226,21 +226,6 @@ public function test_news_sitemap_item_to_xml() {
),
);
- $xml = '' . PHP_EOL
- . ''
- . 'http://example.com/blog-url-about-stuff'
- . "$timestamp"
- . ''
- . ''
- . 'Blog about stuff'
- . 'en'
- . ''
- . 'Stuff with stuff to escape, like less than signs: < and ampersands: &'
- . "$timestamp"
- . 'Blog with some already escaped stuff: &Ł'
- . ''
- . '' . PHP_EOL;
-
foreach (
array(
new Jetpack_Sitemap_Buffer_Dummy( JP_SITEMAP_MAX_ITEMS, JP_SITEMAP_MAX_BYTES, $timestamp ),
@@ -249,9 +234,24 @@ public function test_news_sitemap_item_to_xml() {
) {
$buffer->append( $array );
+ // Normalize the XML by removing whitespace between tags and normalizing newlines
+ $actual = preg_replace( '/>\s+', '><', $buffer->contents() );
+ $actual = str_replace( "\r\n", "\n", $actual );
+
+ $expected = 'http://example.com/blog-url-about-stuff'
+ . "$timestamp"
+ . ''
+ . 'Blog about stuff'
+ . 'en'
+ . ''
+ . 'Stuff with stuff to escape, like less than signs: < and ampersands: &'
+ . "$timestamp"
+ . 'Blog with some already escaped stuff: &Ł'
+ . '' . "\n";
+
$this->assertEquals(
- $xml,
- $buffer->contents(),
+ $expected,
+ $actual,
get_class( $buffer )
);
}