Skip to content

Commit

Permalink
Do not strip knockout comments from .html files
Browse files Browse the repository at this point in the history
This would have been introduced as part of v1.18.1...v1.19.0

ChatGPT may have assisted with the regex
  • Loading branch information
convenient committed Feb 8, 2024
1 parent e94978d commit d955f8d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,51 @@ public function testWebTemplateHtmlVendorFileNonMeaningfulChange()
];
$this->assertEquals($expected, $ignored);
}

/**
*
*/
public function testWebTemplateHtmlKnockout()
{
$this->m2->expects($this->any())
->method('getListOfHtmlFiles')
->willReturn(
[
'app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html',
'vendor/magento/module-ui/view/base/web/templates/grid/knockout.html',
]
);

$reader = new Reader(
$this->testResourcesDir . 'vendor.patch'
);

$entries = $reader->getFiles();
$this->assertNotEmpty($entries, 'We should have a patch file to read');

$entry = $entries[3];

$appCodeGetter = new GetAppCodePathFromVendorPath($this->m2, $entry);
$appCodeFilePath = $appCodeGetter->getAppCodePathFromVendorPath();
$this->assertEquals(
'app/code/Magento/Ui/view/base/web/templates/grid/knockout.html',
$appCodeFilePath
);

$warnings = $infos = $ignored = [];

$check = new WebTemplateHtml($this->m2, $entry, $appCodeFilePath, $warnings, $infos, $ignored);
$this->assertTrue($check->canCheck(), 'Check should be checkable');
$check->check();

$this->assertEmpty($ignored, 'We should have no ignore level items');
$this->assertEmpty($infos, 'We should have no info level items');
$this->assertNotEmpty($warnings, 'We should have a warning');
$expectedWarnings = [
'Override (phtml/js/html)' => [
'app/design/frontend/Ampersand/theme/Magento_Ui/web/templates/grid/knockout.html'
]
];
$this->assertEquals($expectedWarnings, $warnings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>some override</h1>
10 changes: 10 additions & 0 deletions dev/phpunit/unit/resources/checks/WebTemplateHtml/vendor.patch
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,13 @@ diff -ur -N vendor_orig/magento/module-ui/view/base/web/templates/grid/some_noop
-<!-- -->
\ No newline at end of file
+<!-- --> <!-- --> <!-- -->
diff -ur -N vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html vendor/magento/module-ui/view/base/web/templates/grid/knockout.html
--- vendor_orig/magento/module-ui/view/base/web/templates/grid/knockout.html 2024-02-08 20:13:23.000000000 +0000
+++ vendor/magento/module-ui/view/base/web/templates/grid/knockout.html 2024-02-08 20:13:23.000000000 +0000
@@ -1,5 +1,5 @@
<h1>hello</h1>
<h1>goodbye</h1>
-<!-- ko foreach: getRegion('captcha') -->
+<!-- ko foreach: getRegion('somethingweird') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>hello</h1>
<h1>goodbye</h1>
<!-- ko foreach: getRegion('somethingweird') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<h1>hello</h1>
<h1>goodbye</h1>
<!-- ko foreach: getRegion('captcha') -->
<!-- ko template: getTemplate() --><!-- /ko -->
<!-- /ko -->
2 changes: 1 addition & 1 deletion src/Ampersand/PatchHelper/Patchfile/Sanitiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,6 @@ public static function stripCommentsFromHtml($contents)
{
// This regular expression will match and remove both single-line <!-- ... --> comments and multi-line comments
// spanning multiple lines. The s flag is used to make the dot (.) match any character, including newlines.
return preg_replace('/<!--(.*?)-->/s', '', $contents);
return preg_replace('/<!--(?! *ko)(.*?)-->/s', '', $contents);
}
}

0 comments on commit d955f8d

Please sign in to comment.