Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Allow https on scheme without a hostname #3997

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions library/Zend/Mvc/Router/Http/TreeRouteStack.php
Expand Up @@ -225,12 +225,16 @@ public function assemble(array $params = array(), array $options = array())
$uri->setFragment($options['fragment']); $uri->setFragment($options['fragment']);
} }


if ((isset($options['force_canonical']) && $options['force_canonical']) || $uri->getHost() !== null) { if ((isset($options['force_canonical']) && $options['force_canonical']) || $uri->getHost() !== null || $uri->getScheme() !== null) {
if ($uri->getScheme() === null) { if (($uri->getHost() === null || $uri->getScheme() === null) && $this->requestUri === null) {
if ($this->requestUri === null) { throw new Exception\RuntimeException('Request URI has not been set');
throw new Exception\RuntimeException('Request URI has not been set'); }
}
if ($uri->getHost() === null) {
$uri->setHost($this->requestUri->getHost());
}


if ($uri->getScheme() === null) {
$uri->setScheme($this->requestUri->getScheme()); $uri->setScheme($this->requestUri->getScheme());
} }


Expand Down
27 changes: 27 additions & 0 deletions tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php
Expand Up @@ -228,6 +228,33 @@ public function testAssembleWithQueryParams()
$this->assertEquals('/?foo=bar', $stack->assemble(array(), array('name' => 'index', 'query' => array('foo' => 'bar')))); $this->assertEquals('/?foo=bar', $stack->assemble(array(), array('name' => 'index', 'query' => array('foo' => 'bar'))));
} }


public function testAssembleWithScheme()
{
$uri = new HttpUri();
$uri->setScheme('http');
$uri->setHost('example.com');
$stack = new TreeRouteStack();
$stack->setRequestUri($uri);
$stack->addRoute(
'secure',
array(
'type' => 'Scheme',
'options' => array(
'scheme' => 'https'
),
'child_routes' => array(
'index' => array(
'type' => 'Literal',
'options' => array(
'route' => '/',
),
),
),
)
);
$this->assertEquals('https://example.com/', $stack->assemble(array(), array('name' => 'secure/index')));
}

public function testAssembleWithFragment() public function testAssembleWithFragment()
{ {
$stack = new TreeRouteStack(); $stack = new TreeRouteStack();
Expand Down