Issues

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

Issue Type: Unit Tests: Improvement Created: 2008-10-17T00:52:36.000+0000 Last Updated: 2011-06-07T23:20:31.000+0000 Status: Resolved Fix version(s): - 1.11.8 (07/Jul/11)

Reporter: Christopher Nadeau (chroder) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_View

Related issues: - ZF-9000

Attachments:

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

Posted by Ralph Schindler (ralph) on 2011-02-18T14:59:25.000+0000

Is this still an issue?

Posted by Adam Lundrigan (adamlundrigan) on 2011-05-28T23:09:36.000+0000

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

<pre class="highlight">
/**
 * @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.

Posted by Adam Lundrigan (adamlundrigan) on 2011-05-28T23:35:23.000+0000

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

Posted by Adam Lundrigan (adamlundrigan) on 2011-06-07T23:07:07.000+0000

Merged updated unit test to release-1.11 in r24127

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts