diff --git a/.gitignore b/.gitignore
index 6b1842b57..07da74f1e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,10 +12,10 @@
/rainloop/v/0.0.0/static/css/*.css
/rainloop/v/0.0.0/static/js/*.js
/rainloop/v/0.0.0/static/js/**/*.js
-/tests/_config.js
/node_modules
/build/local
/build/dist
/build/tmp
/data
.DS_Store
+/tests/fix.php
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 000000000..857d802c8
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,5 @@
+language: php
+php:
+ - '5.3'
+ - '5.6'
+ - '7.0'
diff --git a/rainloop/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php b/rainloop/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php
index 479a15552..182e8cc2b 100644
--- a/rainloop/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php
+++ b/rainloop/v/0.0.0/app/libraries/MailSo/Base/HtmlUtils.php
@@ -52,7 +52,9 @@ class HtmlUtils
$sText = \MailSo\Base\HtmlUtils::ClearBodyAndHtmlTag($sText, $sHtmlAttrs, $sBodyAttrs);
@$oDom->loadHTML('<'.'?xml version="1.0" encoding="utf-8"?'.'>'.
- '
'.$sText.'
');
+ ''.
+ ''.
+ ''.$sText.'
');
@$oDom->normalizeDocument();
@@ -141,6 +143,18 @@ class HtmlUtils
else
{
$sResult = \trim($oDom->saveHTML($oDiv));
+
+ if (0 === strpos($sResult, ''))
+ {
+ $sResult = substr($sResult, 5);
+
+ if ('
' === substr($sResult, -6))
+ {
+ $sResult = substr($sResult, 0, -6);
+ }
+
+ $sResult = \trim($sResult);
+ }
}
}
else
@@ -175,7 +189,7 @@ class HtmlUtils
$sBodyAttrs = $aMatch[1];
}
- $sHtml = \preg_replace('/]*)>/im', '', $sHtml);
+ $sHtml = \preg_replace('/^.*]*)>/sim', '', $sHtml);
$sHtml = \preg_replace('/<\/body>/im', '', $sHtml);
$sHtml = \preg_replace('/]*)>/im', '', $sHtml);
$sHtml = \preg_replace('/<\/html>/im', '', $sHtml);
@@ -747,18 +761,24 @@ class HtmlUtils
* @param string $sHtml
* @param bool $bDoNotReplaceExternalUrl = false
* @param bool $bFindLinksInHtml = false
+ * @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
- public static function ClearHtmlSimple($sHtml, $bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false)
+ public static function ClearHtmlSimple($sHtml, $bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false, $bWrapByFakeHtmlAndBodyDiv = true)
{
$bHasExternals = false;
$aFoundCIDs = array();
$aContentLocationUrls = array();
$aFoundedContentLocationUrls = array();
+ $fAdditionalExternalFilter = null;
+ $fAdditionalDomReader = null;
+ $bTryToDetectHiddenImages = false;
return \MailSo\Base\HtmlUtils::ClearHtml($sHtml, $bHasExternals, $aFoundCIDs,
- $aContentLocationUrls, $aFoundedContentLocationUrls, $bDoNotReplaceExternalUrl, $bFindLinksInHtml);
+ $aContentLocationUrls, $aFoundedContentLocationUrls, $bDoNotReplaceExternalUrl, $bFindLinksInHtml,
+ $fAdditionalExternalFilter, $fAdditionalDomReader, $bTryToDetectHiddenImages,
+ $bWrapByFakeHtmlAndBodyDiv);
}
/**
@@ -771,6 +791,8 @@ class HtmlUtils
* @param bool $bFindLinksInHtml = false
* @param callback|null $fAdditionalExternalFilter = null
* @param callback|null $fAdditionalDomReader = null
+ * @param bool $bTryToDetectHiddenImages = false
+ * @param bool $bWrapByFakeHtmlAndBodyDiv = true
*
* @return string
*/
@@ -778,7 +800,7 @@ class HtmlUtils
$aContentLocationUrls = array(), &$aFoundedContentLocationUrls = array(),
$bDoNotReplaceExternalUrl = false, $bFindLinksInHtml = false,
$fAdditionalExternalFilter = null, $fAdditionalDomReader = false,
- $bTryToDetectHiddenImages = false)
+ $bTryToDetectHiddenImages = false, $bWrapByFakeHtmlAndBodyDiv = true)
{
$sResult = '';
@@ -1096,7 +1118,7 @@ class HtmlUtils
$oElement->removeAttribute('data-x-skip-style');
}
- $sResult = \MailSo\Base\HtmlUtils::GetTextFromDom($oDom);
+ $sResult = \MailSo\Base\HtmlUtils::GetTextFromDom($oDom, $bWrapByFakeHtmlAndBodyDiv);
}
unset($oDom);
diff --git a/tests/MailSo/Base/HtmlUtilsTest.php b/tests/MailSo/Base/HtmlUtilsTest.php
new file mode 100644
index 000000000..4ef8dd260
--- /dev/null
+++ b/tests/MailSo/Base/HtmlUtilsTest.php
@@ -0,0 +1,21 @@
+assertTrue(true);
+ $this->assertTrue(class_exists('\\RainLoop\\Api'));
+ $this->assertTrue(class_exists('\\MailSo\\Base\\HtmlUtils'));
+ }
+
+ public function testClearHtml()
+ {
+ $i = 0;
+ while (++$i < 3)
+ {
+ $this->assertEquals(file_get_contents(TEST_DATA_FOLDER."/html/{$i}-ok.html"),
+ \MailSo\Base\HtmlUtils::ClearHtmlSimple(file_get_contents(TEST_DATA_FOLDER."/html/{$i}.html"), false, false, false));
+ }
+ }
+}
diff --git a/tests/_data/html/1-ok.html b/tests/_data/html/1-ok.html
new file mode 100644
index 000000000..d800886d9
--- /dev/null
+++ b/tests/_data/html/1-ok.html
@@ -0,0 +1 @@
+123
\ No newline at end of file
diff --git a/tests/_data/html/1.html b/tests/_data/html/1.html
new file mode 100644
index 000000000..c391cf7d3
--- /dev/null
+++ b/tests/_data/html/1.html
@@ -0,0 +1,11 @@
+
+
+
+
+
+123
+
+
\ No newline at end of file
diff --git a/tests/_data/html/2-ok.html b/tests/_data/html/2-ok.html
new file mode 100644
index 000000000..d800886d9
--- /dev/null
+++ b/tests/_data/html/2-ok.html
@@ -0,0 +1 @@
+123
\ No newline at end of file
diff --git a/tests/_data/html/2.html b/tests/_data/html/2.html
new file mode 100644
index 000000000..7d2d2a481
--- /dev/null
+++ b/tests/_data/html/2.html
@@ -0,0 +1,12 @@
+
+
+
+
+
+123
+
+
+
\ No newline at end of file
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index b3d9bbc7f..2582a6963 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -1 +1,6 @@