Skip to content

Commit

Permalink
[TASK] Use Environment API instead of PATH_site in indexed_search
Browse files Browse the repository at this point in the history
Resolves: #85273
Releases: master
Change-Id: If2a643843532d14f2b7263c66b22ad1bc0402c33
Reviewed-on: https://review.typo3.org/57231
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: Jan Helke <typo3@helke.de>
  • Loading branch information
lolli42 authored and janhelke committed Jun 15, 2018
1 parent b5cd555 commit 843f7a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
3 changes: 2 additions & 1 deletion typo3/sysext/indexed_search/Classes/Hook/CrawlerHook.php
Expand Up @@ -15,6 +15,7 @@
*/

use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
Expand Down Expand Up @@ -359,7 +360,7 @@ public function crawler_execute_type2($cfgRec, &$session_data, $params, &$pObj)
}
}
}
$files = GeneralUtility::removePrefixPathFromList($files, PATH_site);
$files = GeneralUtility::removePrefixPathFromList($files, Environment::getPublicPath() . '/');
// traverse the items and create log entries:
foreach ($files as $path) {
$this->instanceCounter++;
Expand Down
21 changes: 11 additions & 10 deletions typo3/sysext/indexed_search/Classes/Indexer.php
Expand Up @@ -16,6 +16,7 @@

use TYPO3\CMS\Core\Compatibility\PublicPropertyDeprecationTrait;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
Expand Down Expand Up @@ -802,7 +803,7 @@ public function extractLinks($content)
if (GeneralUtility::isAllowedAbsPath($linkSource)) {
$localFile = $linkSource;
} else {
$localFile = GeneralUtility::getFileAbsFileName(PATH_site . $linkSource);
$localFile = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $linkSource);
}
if ($localFile && @is_file($localFile)) {
// Index local file:
Expand Down Expand Up @@ -1013,7 +1014,7 @@ protected function createLocalPathUsingDomainURL($sourcePath)
$baseURLLength = strlen($baseURL);
if (substr($sourcePath, 0, $baseURLLength) == $baseURL) {
$sourcePath = substr($sourcePath, $baseURLLength);
$localPath = PATH_site . $sourcePath;
$localPath = Environment::getPublicPath() . '/' . $sourcePath;
if (!self::isAllowedLocalFile($localPath)) {
$localPath = '';
}
Expand All @@ -1036,7 +1037,7 @@ protected function createLocalPathUsingAbsRefPrefix($sourcePath)
$absRefPrefixLength = strlen($absRefPrefix);
if ($absRefPrefixLength > 0 && substr($sourcePath, 0, $absRefPrefixLength) == $absRefPrefix) {
$sourcePath = substr($sourcePath, $absRefPrefixLength);
$localPath = PATH_site . $sourcePath;
$localPath = Environment::getPublicPath() . '/' . $sourcePath;
if (!self::isAllowedLocalFile($localPath)) {
$localPath = '';
}
Expand All @@ -1057,7 +1058,7 @@ protected function createLocalPathFromAbsoluteURL($sourcePath)
$localPath = '';
if ($sourcePath[0] === '/') {
$sourcePath = substr($sourcePath, 1);
$localPath = PATH_site . $sourcePath;
$localPath = Environment::getPublicPath() . '/' . $sourcePath;
if (!self::isAllowedLocalFile($localPath)) {
$localPath = '';
}
Expand All @@ -1075,7 +1076,7 @@ protected function createLocalPathFromRelativeURL($sourcePath)
{
$localPath = '';
if (self::isRelativeURL($sourcePath)) {
$localPath = PATH_site . $sourcePath;
$localPath = Environment::getPublicPath() . '/' . $sourcePath;
if (!self::isAllowedLocalFile($localPath)) {
$localPath = '';
}
Expand Down Expand Up @@ -1104,7 +1105,7 @@ protected static function isRelativeURL($url)
protected static function isAllowedLocalFile($filePath)
{
$filePath = GeneralUtility::resolveBackPath($filePath);
$insideWebPath = substr($filePath, 0, strlen(PATH_site)) == PATH_site;
$insideWebPath = substr($filePath, 0, strlen(Environment::getPublicPath())) === Environment::getPublicPath();
$isFile = is_file($filePath);
return $insideWebPath && $isFile;
}
Expand All @@ -1115,9 +1116,9 @@ protected static function isAllowedLocalFile($filePath)
*
******************************************/
/**
* Indexing a regular document given as $file (relative to PATH_site, local file)
* Indexing a regular document given as $file (relative to public web path, local file)
*
* @param string $file Relative Filename, relative to PATH_site. It can also be an absolute path as long as it is inside the lockRootPath (validated with \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath()). Finally, if $contentTmpFile is set, this value can be anything, most likely a URL
* @param string $file Relative Filename, relative to public web path. It can also be an absolute path as long as it is inside the lockRootPath (validated with \TYPO3\CMS\Core\Utility\GeneralUtility::isAbsPath()). Finally, if $contentTmpFile is set, this value can be anything, most likely a URL
* @param bool $force If set, indexing is forced (despite content hashes, mtime etc).
* @param string $contentTmpFile Temporary file with the content to read it from (instead of $file). Used when the $file is a URL.
* @param string $altExtension File extension for temporary file.
Expand All @@ -1130,8 +1131,8 @@ public function indexRegularDocument($file, $force = false, $contentTmpFile = ''
// Create abs-path:
if (!$contentTmpFile) {
if (!GeneralUtility::isAbsPath($file)) {
// Relative, prepend PATH_site:
$absFile = GeneralUtility::getFileAbsFileName(PATH_site . $file);
// Relative, prepend public web path:
$absFile = GeneralUtility::getFileAbsFileName(Environment::getPublicPath() . '/' . $file);
} else {
// Absolute, pass-through:
$absFile = $file;
Expand Down
16 changes: 8 additions & 8 deletions typo3/sysext/indexed_search/Tests/Unit/IndexerTest.php
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\IndexedSearch\Indexer;
use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
Expand Down Expand Up @@ -50,7 +51,7 @@ public function extractHyperLinksDoesNotReturnNonExistingLocalPath()
*/
public function extractHyperLinksReturnsCorrectFileUsingT3Vars()
{
$temporaryFileName = tempnam(PATH_site . 'typo3temp/var/tests/', 't3unit-');
$temporaryFileName = tempnam(Environment::getVarPath() . '/tests/', 't3unit-');
$this->testFilesToDelete[] = $temporaryFileName;
$html = 'test <a href="testfile">test</a> test';
$GLOBALS['T3_VAR']['ext']['indexed_search']['indexLocalFiles'] = [
Expand All @@ -65,14 +66,14 @@ public function extractHyperLinksReturnsCorrectFileUsingT3Vars()
/**
* @test
*/
public function extractHyperLinksRecurnsCorrectPathWithBaseUrl()
public function extractHyperLinksReturnsCorrectPathWithBaseUrl()
{
$baseURL = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
$html = 'test <a href="' . $baseURL . 'index.php">test</a> test';
$subject = new Indexer();
$result = $subject->extractHyperLinks($html);
$this->assertEquals(1, count($result));
$this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
$this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
}

/**
Expand All @@ -84,20 +85,19 @@ public function extractHyperLinksFindsCorrectPathWithAbsolutePath()
$subject = new Indexer();
$result = $subject->extractHyperLinks($html);
$this->assertEquals(1, count($result));
$this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
$this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
}

/**
* @test
*/
public function extractHyperLinksFindsCorrectPathForPathWithinTypo3Directory()
{
$path = substr(PATH_typo3, strlen(PATH_site) - 1);
$html = 'test <a href="' . $path . 'index.php">test</a> test';
$html = 'test <a href="typo3/index.php">test</a> test';
$subject = new Indexer();
$result = $subject->extractHyperLinks($html);
$this->assertEquals(1, count($result));
$this->assertEquals(PATH_typo3 . 'index.php', $result[0]['localPath']);
$this->assertEquals(Environment::getPublicPath() . '/typo3/index.php', $result[0]['localPath']);
}

/**
Expand All @@ -117,7 +117,7 @@ public function extractHyperLinksFindsCorrectPathUsingAbsRefPrefix()
$subject = new Indexer();
$result = $subject->extractHyperLinks($html);
$this->assertEquals(1, count($result));
$this->assertEquals(PATH_site . 'index.php', $result[0]['localPath']);
$this->assertEquals(Environment::getPublicPath() . '/index.php', $result[0]['localPath']);
}

/**
Expand Down

0 comments on commit 843f7a9

Please sign in to comment.