Skip to content

Commit

Permalink
[BUGFIX] Handle new _assets/ path correctly
Browse files Browse the repository at this point in the history
Close: #1865
  • Loading branch information
NamelessCoder committed Jul 12, 2023
1 parent f13fbf3 commit 8f79887
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Classes/Service/AssetService.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\ArrayUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Extbase\Utility\DebuggerUtility;
use TYPO3\CMS\Fluid\View\StandaloneView;
Expand Down Expand Up @@ -232,21 +233,17 @@ protected function buildAssetsChunk(array $assets): string
if ($rewrite) {
$chunks[] = $this->writeCachedMergedFileAndReturnTag([$name => $asset], $type);
} else {
$integrity = $this->getFileIntegrity($path);
$path = mb_substr($path, mb_strlen(CoreUtility::getSitePath()));
$path = $this->prefixPath($path);
$chunks[] = $this->generateTagForAssetType(
$type,
null,
$path,
$integrity,
$this->getFileIntegrity($path),
$assetSettings
);
}
}
}
}
unset($integrity);
}
if (0 < count($chunk)) {
$mergedFileTag = $this->writeCachedMergedFileAndReturnTag($chunk, $type);
Expand Down Expand Up @@ -333,6 +330,10 @@ protected function generateTagForAssetType(
if (empty($type) && !empty($file)) {
$type = pathinfo($file, PATHINFO_EXTENSION);
}
if ($file !== null) {
$file = PathUtility::getAbsoluteWebPath($file);
$file = $this->prefixPath($file);
}
switch ($type) {
case 'js':
$tagBuilder->setTagName('script');
Expand Down Expand Up @@ -514,9 +515,7 @@ protected function prefixPath(string $fileRelativePathAndFilename): string
{
$settings = $this->getSettings();
$prefixPath = $settings['prependPath'] ?? '';
if (!empty($GLOBALS['TSFE']->absRefPrefix) && empty($prefixPath)) {
$fileRelativePathAndFilename = $GLOBALS['TSFE']->absRefPrefix . $fileRelativePathAndFilename;
} elseif (!empty($prefixPath)) {
if (!empty($prefixPath)) {
$fileRelativePathAndFilename = $prefixPath . $fileRelativePathAndFilename;
}
return $fileRelativePathAndFilename;
Expand Down Expand Up @@ -709,7 +708,7 @@ protected function mergeArrays(array $array1, array $array2): array
return $array1;
}

protected function getFileIntegrity(string $file): string
protected function getFileIntegrity(string $file): ?string
{
$typoScript = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_vhs.'] ?? null;
if (isset($typoScript['assets.']['tagsAddSubresourceIntegrity'])) {
Expand All @@ -718,7 +717,7 @@ protected function getFileIntegrity(string $file): string
&& $typoScript['assets.']['tagsAddSubresourceIntegrity'] < 4
) {
if (!file_exists($file)) {
return '';
return null;
}

/** @var TypoScriptFrontendController $typoScriptFrontendController */
Expand Down Expand Up @@ -747,14 +746,14 @@ protected function getFileIntegrity(string $file): string
(string) openssl_digest((string) file_get_contents($file), $integrityMethod, true)
);
} else {
return ''; // Sadly, no integrity generation possible
return null; // Sadly, no integrity generation possible
}
$this->writeFile($integrityFile, $integrity);
}
return sprintf('%s-%s', $integrityMethod, $integrity ?: (string) file_get_contents($integrityFile));
}
}
return '';
return null;
}

private function getTempPath(): string
Expand Down

0 comments on commit 8f79887

Please sign in to comment.