From 6b6118e9e8d69c8c9226877a3494a62f09891a56 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Fri, 2 May 2025 14:51:16 +0200 Subject: [PATCH 1/4] fix(ActionSlackNotification): Improve TransformHTMLToSlackMarkup with current CKEditor --- datamodel.combodo-webhook-integration.xml | 26 ++++++++++------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/datamodel.combodo-webhook-integration.xml b/datamodel.combodo-webhook-integration.xml index 43f4fff..7f28b42 100644 --- a/datamodel.combodo-webhook-integration.xml +++ b/datamodel.combodo-webhook-integration.xml @@ -1749,26 +1749,22 @@ protected function ApplyParamsToJson(array $aContextArgs, string $sInputAsJson) } $aReplacementsMatrix = array( - array( array('
', '
', '
'), "\n" ), - array( array('

', '

'), array('*', '*') ), - array( array('

', '

'), array('*', '*') ), - array( array('

', '

'), array('*', '*') ), - array( array('', ''), array('*', '*') ), - array( array('', ''), array('*', '*') ), - array( array('', ''), array('_', '_') ), - array( array('', ''), array('_', '_') ), - array( array('', ''), array('~', '~') ), - array( array('', ''), array('~', '~') ), - array( array('
  • ', '
  • '), array('• ', '') ), - array( array('', ''), array('`', '`') ), - array( array('
    ', '
    '), array('```', '```') ), + [ '##i', "\n" ], + [ ['#

    #i', '#

    #i'], ['', "\n"] ], + [ ['##i', '##i'], ['*', "*\n"] ], + [ ['#<(strong|b)>#i', '##i'], '*' ], + [ ['#<(em|i)>#i', '##i'], '_' ], + [ ['#<(del|s)>#i', '##i'], '~' ], + [ ['#
  • #i', '#
  • #i'], ['• ', "\n"] ], + [ ['#
    (]*>)?#i', '#()?
    #i'], ['```', "```\n"] ], + [ ['#<(mark[^>]*|code)>#i', '##i'], '`' ], ); // Replace HTML tags (list must contain at least tags from the $aReplacementsMatrix) - $sContent = strip_tags($sContent, '


  • ');
    +		$sContent = strip_tags($sContent, '

  • ');
     		foreach($aReplacementsMatrix as $aReplacements)
     		{
    -			$sContent = str_replace($aReplacements[0], $aReplacements[1], $sContent);
    +			$sContent = preg_replace($aReplacements[0], $aReplacements[1], $sContent);
     		}
     
     		// Replace hyperlinks
    
    From 51b422d75313e00f1b8d8b5d0736bd03984508a3 Mon Sep 17 00:00:00 2001
    From: jf-cbd 
    Date: Fri, 16 May 2025 15:22:26 +0200
    Subject: [PATCH 2/4] Add test to avoid future potential regressions on
     different tags (and also prevent the new line issue)
    
    ---
     tests/php-unit-tests/ActionSlackNotificationTest.php | 6 ++++++
     1 file changed, 6 insertions(+)
    
    diff --git a/tests/php-unit-tests/ActionSlackNotificationTest.php b/tests/php-unit-tests/ActionSlackNotificationTest.php
    index e4f1bc4..ee8b43d 100644
    --- a/tests/php-unit-tests/ActionSlackNotificationTest.php
    +++ b/tests/php-unit-tests/ActionSlackNotificationTest.php
    @@ -53,6 +53,12 @@ public function TransformHTMLToSlackMarkupProvider(): array
     HTML,
     				"expected" => "",
     			],
    +			"Large text with different tags" => [
    +				"input" => <<Heading 1
  • Heading 2

    Heading 3

    Strong Text
    Bold Text
    Emphasized Text
    Italic Text
    Deleted Text
    Strikethrough Text
     

    Inline Code
     

    Block of Code\r\nLine 1\r\nLine 2\r\n
    +HTML, + "expected" => "*Heading 1*\n*Heading 2*\n*Heading 3*\n*Strong Text*\n*Bold Text*\n_Emphasized Text_\n_Italic Text_\n~Deleted Text~\n~Strikethrough Text~\n \n• List Item 1\n• List Item 2\n`Inline Code`\n \n```Block of Code\r\nLine 1\r\nLine 2\r\n```\n", + ], ]; } } From 6c69df1b61dcd4c615fc8686d49a12f4534f6cf2 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Mon, 19 May 2025 11:01:48 +0200 Subject: [PATCH 3/4] Fix test --- tests/php-unit-tests/ActionSlackNotificationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/php-unit-tests/ActionSlackNotificationTest.php b/tests/php-unit-tests/ActionSlackNotificationTest.php index ee8b43d..403051e 100644 --- a/tests/php-unit-tests/ActionSlackNotificationTest.php +++ b/tests/php-unit-tests/ActionSlackNotificationTest.php @@ -55,9 +55,9 @@ public function TransformHTMLToSlackMarkupProvider(): array ], "Large text with different tags" => [ "input" => <<Heading 1
  • Heading 2

    Heading 3

    Strong Text
    Bold Text
    Emphasized Text
    Italic Text
    Deleted Text
    Strikethrough Text
     

    Inline Code
     

    Block of Code\r\nLine 1\r\nLine 2\r\n
    +

    Heading 1

    Heading 2

    Heading 3

    Strong Text
    Bold Text
    Emphasized Text
    Italic Text
    Deleted Text
    Strikethrough Text
    Marked Text
    Inline Code

    • List Item 1
    • List Item 2
    Block of Code\r\nLine 1\r\nLine 2\r\n
    HTML, - "expected" => "*Heading 1*\n*Heading 2*\n*Heading 3*\n*Strong Text*\n*Bold Text*\n_Emphasized Text_\n_Italic Text_\n~Deleted Text~\n~Strikethrough Text~\n \n• List Item 1\n• List Item 2\n`Inline Code`\n \n```Block of Code\r\nLine 1\r\nLine 2\r\n```\n", + "expected" => "*Heading 1*\n*Heading 2*\n*Heading 3*\n*Strong Text*\n*Bold Text*\n_Emphasized Text_\n_Italic Text_\n~Deleted Text~\n~Strikethrough Text~\n`Marked Text`\n`Inline Code`\n• List Item 1\n• List Item 2\n```Block of Code\r\nLine 1\r\nLine 2\r\n```\n", ], ]; } From 4c19b00a00c6efde35f48bf566c02f6eb7fe5a37 Mon Sep 17 00:00:00 2001 From: Thomas Casteleyn Date: Mon, 19 May 2025 14:34:19 +0200 Subject: [PATCH 4/4] Additional tests --- .../ActionSlackNotificationTest.php | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/tests/php-unit-tests/ActionSlackNotificationTest.php b/tests/php-unit-tests/ActionSlackNotificationTest.php index 403051e..04110df 100644 --- a/tests/php-unit-tests/ActionSlackNotificationTest.php +++ b/tests/php-unit-tests/ActionSlackNotificationTest.php @@ -53,12 +53,30 @@ public function TransformHTMLToSlackMarkupProvider(): array HTML, "expected" => "", ], + "Simple p tags on different lines" => [ + "input" => <<hello

    hi

    +HTML, + "expected" => "hello\nhi\n", + ], + "Different tags on different lines" => [ + "input" => <<hello

    hi

    +HTML, + "expected" => "*hello*\n*hi*\n", + ], + "Nested tags" => [ + "input" => <<I'm bold and

    I'm bold and italic

    +HTML, + "expected" => "*I'm bold and*\n_*I'm bold and italic*_\n", + ], "Large text with different tags" => [ "input" => <<Heading 1

    Heading 2

    Heading 3

    Strong Text
    Bold Text
    Emphasized Text
    Italic Text
    Deleted Text
    Strikethrough Text
    Marked Text
    Inline Code

    • List Item 1
    • List Item 2
    Block of Code\r\nLine 1\r\nLine 2\r\n
    HTML, "expected" => "*Heading 1*\n*Heading 2*\n*Heading 3*\n*Strong Text*\n*Bold Text*\n_Emphasized Text_\n_Italic Text_\n~Deleted Text~\n~Strikethrough Text~\n`Marked Text`\n`Inline Code`\n• List Item 1\n• List Item 2\n```Block of Code\r\nLine 1\r\nLine 2\r\n```\n", - ], + ], ]; } }