ZF-4622: Zend_View_Abstract::_addPath() strips double-slash from protocol

Description

This code is run on the path in Zend_View_Abstract::_addPath(): {{$dir = rtrim($dir, DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;}}

This should be removed/improved because it prevents you from using custom stream wrappers. For example, I have implemented a few custom wrappers to work with a different template engine. Instead of hacking everything to work from non-filesystem sources, I just created some stream wrappers to do it behind the scenes. I register the protocol 'tpl', and then set the script path to 'tpl://' (i.e., to load a 'tpl://emaple.html' template). But the code above strips off the extra slash so ZF tries to load 'tpl:/example.html' which is incorrect.

Furthermore, the _addPath method is private so I can't override it in a subclass.

For now what I've been doing to work around the problem is to set the script path to 'tpl://null/' to stop the rtrim from stripping the double slash from the protocol part.

Comments

Is this still an issue?

No. The unit test for ZF-9000 shows that this issue no longer exists:


/**
 * @group ZF-9000
 */
public function testAddingStreamSchemeAsScriptPathShouldNotReverseSlashesOnWindows()
{
    if (false === strstr(strtolower(PHP_OS), 'windows')) {
        $this->markTestSkipped('Windows-only test');
    }
    $view = new Zend_View();
    $path = rtrim('file://' . str_replace('\\', '/', realpath(dirname(__FILE__))), '/') . '/';
    $view->addScriptPath($path);
    $paths = $view->getScriptPaths();
    $this->assertContains($path, $paths, var_export($paths, 1));
}

It successfully adds a view path using the file:// scheme. This unit test should be generalized for all platforms.

Added adapted unit test to trunk r24076 * Renamed test to: testAddingStreamSchemeAsScriptPathShouldNotMangleThePath * Removed Windows-only constraint

Merged updated unit test to release-1.11 in r24127