diff --git a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
index 90144639..6c8a67f2 100644
--- a/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
+++ b/Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
@@ -94,6 +94,11 @@ public function process(File $phpcsFile, $stackPtr): void
$original = $token['content'];
$replacement = str_replace(' />', '>', $original);
$replacement = str_replace('/>', '>', $replacement);
+
+ if (preg_match('{^\s* />}', $original)) {
+ $replacement = ' ' . $replacement;
+ }
+
$phpcsFile->fixer->replaceToken($ptr, $replacement);
}
}
diff --git a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
index 5fd75e3d..7c3cf9bc 100644
--- a/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
+++ b/Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
@@ -84,6 +84,11 @@ public function process(File $phpcsFile, $stackPtr)
$original = $token['content'];
$replacement = str_replace(' />', '>' . $match[1] . '>', $original);
$replacement = str_replace('/>', '>' . $match[1] . '>', $replacement);
+
+ if (preg_match('{^\s* />}', $original)) {
+ $replacement = ' ' . $replacement;
+ }
+
$phpcsFile->fixer->replaceToken($ptr, $replacement);
}
}
diff --git a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed
index 0b04c24f..42b503a0 100644
--- a/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed
+++ b/Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.inc.fixed
@@ -25,7 +25,7 @@
+ >
diff --git a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed
index cf12aa1b..38f04704 100644
--- a/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed
+++ b/Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.1.inc.fixed
@@ -40,7 +40,7 @@
+ >