Skip to content
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
3 changes: 0 additions & 3 deletions .coveralls.yml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ on:

jobs:
build:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0', '8.1']
php-versions: ['7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/coverage/
/vendor/
/clover.xml
.*
Comment thread
chadicus marked this conversation as resolved.
composer.lock
phpunit.xml
!/.github/
!.gitattributes
31 changes: 0 additions & 31 deletions .scrutinizer.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

17 changes: 0 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,6 @@
"name": "traderinteractive/util-http",
"description": "A collection of http classes.",
"keywords": ["utility", "http"],
"authors": [
{
"name": "Chad Gray",
"email": "chadwickgray@gmail.com",
"role": "Developer"
},
{
"name": "Spencer Rinehart",
"email": "anubis@overthemonkey.com",
"role": "Developer"
},
{
"name": "Jonathan Gaillard",
"email": "jonathan.gaillard@dominionenterprises.com",
"role": "Developer"
}
],
"license": "MIT",
"config": {
"sort-packages": true
Expand Down
12 changes: 10 additions & 2 deletions src/Util/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function buildQueryString(array $parameters) : string
public static function getQueryParams(string $url, array $collapsedParams = []) : array
{
$queryString = parse_url($url, PHP_URL_QUERY);
if (!is_string($queryString)) {
if (!is_string($queryString) || trim($queryString) === '') {
return [];
}

Expand All @@ -187,6 +187,10 @@ public static function getQueryParams(string $url, array $collapsedParams = [])
list($name, $value) = $nameAndValue;
}

if ($name === '' && $value === '') {
continue;
}

$name = rawurldecode($name);
$value = rawurldecode($value);
$collapsed = isset($collapsedParams[$name]);
Expand Down Expand Up @@ -223,7 +227,7 @@ public static function getQueryParams(string $url, array $collapsedParams = [])
public static function getQueryParamsCollapsed(string $url, array $expectedArrayParams = []) : array
{
$queryString = parse_url($url, PHP_URL_QUERY);
if (!is_string($queryString)) {
if (!is_string($queryString) || trim($queryString) === '') {
return [];
}

Expand All @@ -236,6 +240,10 @@ public static function getQueryParamsCollapsed(string $url, array $expectedArray
list($name, $value) = $nameAndValue;
}

if ($name === '' && $value === '') {
continue;
}

$name = rawurldecode($name);
$value = rawurldecode($value);

Expand Down
64 changes: 64 additions & 0 deletions tests/Util/HttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,38 @@ public function getQueryParamsWithCollapsed()
$this->assertSame(['stuff' => 'yeah', 'moreStuff' => ['mhmm']], $result);
}

/**
* @test
* @covers ::getQueryParams
* @dataProvider provideInvalidGetQueryParamData
*/
public function getQueryParamsWithInvalidUrls(string $url, array $expected)
{
$this->assertSame($expected, Http::getQueryParams($url));
}

public static function provideInvalidGetQueryParamData(): array
{
return [
'empty query string' => [
'url' => 'http://example.com/widgets/123?',
'expected' => [],
],
'malformed url' => [
'url' => 'http:///example.com/widgets/123',
'expected' => [],
],
'trailing &' => [
'url' => 'http://example.com/widgets?a=b&',
'expected' => ['a' => ['b']],
],
'leading &' => [
'url' => 'http://example.com/widgets?&a=b',
'expected' => ['a' => ['b']],
],
];
}

/**
* @test
* @covers ::getQueryParams
Expand Down Expand Up @@ -299,4 +331,36 @@ public function getQueryParamsCollapsedEmptyParameter()
$expected = ['stuff' => 'yeah', 'moreStuff' => ['', 'jazz'], 'otherStuff' => ''];
$this->assertSame($expected, Http::getQueryParamsCollapsed($url, ['moreStuff']));
}

/**
* @test
* @covers ::getQueryParamsCollapsed
* @dataProvider provideInvalidGetQueryParamCollapsedData
*/
public function getQueryParamsCollapsedWithInvalidUrls(string $url, array $expected)
{
$this->assertSame($expected, Http::getQueryParamsCollapsed($url));
}

public static function provideInvalidGetQueryParamCollapsedData(): array
{
return [
'empty query string' => [
'url' => 'http://example.com/widgets/123?',
'expected' => [],
],
'malformed url' => [
'url' => 'http:///example.com/widgets/123',
'expected' => [],
],
'trailing &' => [
'url' => 'http://example.com/widgets?a=b&',
'expected' => ['a' => 'b'],
],
'leading &' => [
'url' => 'http://example.com/widgets?&a=b',
'expected' => ['a' => 'b'],
],
];
}
}
Loading