[BUGFIX] Allow file:// links in Element Browser 29/37329/2
authorNicole Cordes <typo3@cordes.co>
Fri, 27 Feb 2015 19:20:36 +0000 (20:20 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 28 Feb 2015 17:39:49 +0000 (18:39 +0100)
Due to FAL checks it's not possible to link to a file:// resource as
external link. This patch checks for correct "file:" prefix for FAL
relations and allows the use of file:// as external link scheme.

Furthermore a Javascript error is resolved which prevents the closing
of the Element Browser in Chrome.

Releases: master, 6.2
Resolves: #65358
Change-Id: I706fd975654bf82a0830d9901f08ae9de7cc49bf
Reviewed-on: http://review.typo3.org/37329
Reviewed-by: Stephan Gro├čberndt <stephan@grossberndt.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Html/RteHtmlParser.php
typo3/sysext/recordlist/Classes/Browser/ElementBrowser.php
typo3/sysext/rtehtmlarea/Resources/Public/JavaScript/Plugins/TYPO3Link.js

index 39c8d09..c8ff95c 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Html;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Core\Resource;
 
 /**
@@ -679,7 +680,7 @@ class RteHtmlParser extends \TYPO3\CMS\Core\Html\HtmlParser {
                                } else {
                                        // Check for FAL link-handler keyword:
                                        list($linkHandlerKeyword, $linkHandlerValue) = explode(':', trim($link_param), 2);
-                                       if ($linkHandlerKeyword === 'file') {
+                                       if ($linkHandlerKeyword === 'file' && !StringUtility::beginsWith($link_param, 'file://')) {
                                                $href = $siteUrl . '?' . $linkHandlerKeyword . ':' . rawurlencode($linkHandlerValue);
                                        } else {
                                                $fileChar = (int)strpos($link_param, '/');
index 7f1333f..dd29d0b 100644 (file)
@@ -31,6 +31,7 @@ use TYPO3\CMS\Core\Resource\ProcessedFile;
 use TYPO3\CMS\Core\Resource\ResourceFactory;
 use TYPO3\CMS\Core\Utility\File\BasicFileUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Backend\Utility\IconUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
@@ -2379,7 +2380,7 @@ class ElementBrowser {
                        if (count($specialParts) == 2) {
                                $info['value'] = '#_SPECIAL' . $specialParts[1];
                                $info['act'] = 'spec';
-                       } elseif (strpos($href, 'file:') !== FALSE) {
+                       } elseif (StringUtility::beginsWith($href, 'file:') && !StringUtility::beginsWith($href, 'file://')) {
                                $rel = substr($href, strpos($href, 'file:') + 5);
                                $rel = rawurldecode($rel);
                                // resolve FAL-api "file:UID-of-sys_file-record" and "file:combined-identifier"
@@ -2393,7 +2394,7 @@ class ElementBrowser {
                                } else {
                                        $info['value'] = $rel;
                                }
-                       } elseif (GeneralUtility::isFirstPartOfStr($href, $siteUrl)) {
+                       } elseif (StringUtility::beginsWith($href, $siteUrl)) {
                                // If URL is on the current frontend website:
                                // URL is a file, which exists:
                                if (file_exists(PATH_site . rawurldecode($href))) {
index 13c6c65..6d30bc6 100644 (file)
@@ -255,8 +255,7 @@ define('TYPO3/CMS/Rtehtmlarea/Plugins/TYPO3Link',
                                        this.setLinkAttributes(node, range, cur_target, cur_class, cur_title, imageNode, addIconAfterLink, additionalValues);
                                }
                                // Set the selection on the last link created
-                               var links = node.getElementsByTagName('a');
-                               this.editor.getSelection().selectNodeContents(links[links.length-1]);
+                               this.editor.getSelection().selectNodeContents(node);
                        }
                        this.close();
                },
@@ -320,7 +319,7 @@ define('TYPO3/CMS/Rtehtmlarea/Plugins/TYPO3Link',
                                                }
                                        }
                                        if (UserAgent.isGecko) {
-                                               node.href = decodeURI(node.href);
+                                               node.href = decodeURI(node.getAttributeNode('href').value);
                                        }
                                        if (cur_target.trim()) node.target = cur_target.trim();
                                                else node.removeAttribute('target');