Bug #73675

URLs with spaces in the RTE

Added by Marco Huber about 5 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2016-02-25
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Sometimes there could be spaces in a link inserted in the RTE, f.e. if you link to a local file (file:///C:\my\Path is\sö\crazy with everything.pdf) as external URL. Then there should be wrapped some " around the url part of the typo3 link tag, like it is already done in all other link fields (f.e. the field header_link). Otherwise, when the link tag is parsed, some parts of the URL are used as target, class and title.

In \TYPO3\CMS\Core\Html\RteHtmlParser::TS_links_db() we should use the function TypoLinkCodecService::encode().
IMO the cleanest solution would be:

@@ -595,9 +595,6 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                 }
                 // Only if href, target, class and tile are the only attributes, we can alter the link!
                 if (empty($attribArray_copy)) {
-                    // Quoting class and title attributes if they contain spaces
-                    $attribArray['class'] = preg_match('/ /', $attribArray['class']) ? '"' . $attribArray['class'] . '"' : $attribArray['class'];
-                    $attribArray['title'] = preg_match('/ /', $attribArray['title']) ? '"' . $attribArray['title'] . '"' : $attribArray['title'];
                     // Creating the TYPO3 pseudo-tag "<LINK>" for the link (includes href/url, target and class attributes):
                     // If data-htmlarea-external attribute is set, keep the href unchanged
                     if ($attribArray['data-htmlarea-external']) {
@@ -605,7 +602,8 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser
                     } else {
                         $href = $info['url'] . ($info['query'] ? ',0,' . $info['query'] : '');
                     }
-                    $bTag = '<link ' . $href . ($attribArray['target'] ? ' ' . $attribArray['target'] : ($attribArray['class'] || $attribArray['title'] ? ' -' : '')) . ($attribArray['class'] ? ' ' . $attribArray['class'] : ($attribArray['title'] ? ' -' : '')) . ($attribArray['title'] ? ' ' . $attribArray['title'] : '') . '>';
+                    $typoLink = GeneralUtility::makeInstance(TypoLinkCodecService::class)->encode(array('url' => $href, 'target' => $attribArray['target'], 'class' => $attribArray['class'], 'title' => $attribArray['title'], 'additionalParams' => ''));
+                    $bTag = '<link ' . $typoLink . '>';
                     $eTag = '</link>';
                     // Modify parameters
                     if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc'])) {


But this would be a breaking change, because we change the value of $attribArray['title'] and $attribArray['class'] in the hook $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_parsehtml_proc.php']['modifyParams_LinksDb_PostProc'].
So that's why I remove the " from $attribArray['title'] and $attribArray['class'] manually in my patch.

#1

Updated by Gerrit Code Review about 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/46896

#2

Updated by Gerrit Code Review about 5 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/46896

#3

Updated by Markus Klein about 5 years ago

file:///C:\my\Path is\sö\crazy with everything.pdf is an invalid URL, isn't it?
all spaces must be %20 to be a valid URL.

#4

Updated by Marco Huber about 5 years ago

Usecase:

Our customer uses TYPO3 as an intranet in a Windows world. There the editors are used to do a right click on a file in the Windows Explorer, select "Path copy" => "Copy long path" or "Copy long UNC path" and insert this as an External URL in TYPO3. This works perfectly fine in URL fields like the header link. But it does not work in the RTE.

#5

Updated by Gerrit Code Review about 5 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/46896

#6

Updated by Gerrit Code Review about 5 years ago

Patch set 1 for branch TYPO3_7-6 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/47316

#7

Updated by Marco Huber about 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#8

Updated by Benni Mack over 2 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF