10000 Added different protocols to be allowed as asset base_url by alexander-schranz · Pull Request #28476 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Added different protocols to be allowed as asset base_url #28476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Symfony/Component/Asset/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.2.0
-----

* added different protocols to be allowed as asset base_urls

3.4.0
-----

Expand Down
21 changes: 19 additions & 2 deletions src/Symfony/Component/Asset/Tests/UrlPackageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,28 @@ public function getConfigs()
array('http://example.net', '', 'http://example.com/foo', 'http://example.com/foo'),
array('http://example.net', '', 'https://example.com/foo', 'https://example.com/foo'),
array('http://example.net', '', '//example.com/foo', '//example.com/foo'),
array('file:///example/net', '', 'file:///example/com/foo', 'file:///example/com/foo'),
array('ftp://example.net', '', 'ftp://example.com', 'ftp://example.com'),

array('http://example.com', '', '/foo', 'http://example.com/foo?v1'),
array('http://example.com', '', 'foo', 'http://example.com/foo?v1'),
array('http://example.com/', '', 'foo', 'http://example.com/foo?v1'),
array('http://example.com/foo', '', 'foo', 'http://example.com/foo/foo?v1'),
array('http://example.com/foo/', '', 'foo', 'http://example.com/foo/foo?v1'),
array('file:///example/com/foo/', '', 'foo', 'file:///example/com/foo/foo?v1'),

array(array('http://example.com'), '', '/foo', 'http://example.com/foo?v1'),
array(array('http://example.com', 'http://example.net'), '', '/foo', 'http://example.com/foo?v1'),
array(array('http://example.com', 'http://example.net'), '', '/fooa', 'http://example.net/fooa?v1'),
array(array('file:///example/com', 'file:///example/net'), '', '/foo', 'file:///example/com/foo?v1'),
array(array('ftp://example.com', 'ftp://example.net'), '', '/fooa', 'ftp://example.net/fooa?v1'),

array('http://example.com', 'version-%2$s/%1$s', '/foo', 'http://example.com/version-v1/foo'),
array('http://example.com', 'version-%2$s/%1$s', 'foo', 'http://example.com/version-v1/foo'),
array('http://example.com', 'version-%2$s/%1$s', 'foo/', 'http://example.com/version-v1/foo/'),
array('http://example.com', 'version-%2$s/%1$s', '/foo/', 'http://example.com/version-v1/foo/'),
array('file:///example/com', 'version-%2$s/%1$s', '/foo/', 'file:///example/com/version-v1/foo/'),
array('ftp://example.com', 'version-%2$s/%1$s', '/foo/', 'ftp://example.com/version-v1/foo/'),
);
}

Expand Down Expand Up @@ -97,11 +104,21 @@ public function testNoBaseUrls()
}

/**
* @dataProvider getWrongBaseUrlConfig
*
* @expectedException \Symfony\Component\Asset\Exception\InvalidArgumentException
*/
public function testWrongBaseUrl()
public function testWrongBaseUrl($baseUrls)
{
new UrlPackage(array('not-a-url'), new EmptyVersionStrategy());
new UrlPackage($baseUrls, new EmptyVersionStrategy());
}

public function getWrongBaseUrlConfig()
{
return array(
array('not-a-url'),
array('not-a-url-with-query?query=://'),
);
}

private function getContext($secure)
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Asset/UrlPackage.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function getSslUrls($urls)
foreach ($urls as $url) {
if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we support any protocol, should we add other well-known secure protocols here, such as sftp://?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if only relevant browser (http) secure protocols should listed here. If needed I can add sftp.

$sslUrls[] = $url;
} elseif ('http://' !== substr($url, 0, 7)) {
} elseif (null === parse_url($url, PHP_URL_SCHEME)) {
throw new InvalidArgumentException(sprintf('"%s" is not a valid URL', $url));
}
}
Expand Down
0