diff --git a/.coveralls.yml b/.coveralls.yml deleted file mode 100644 index 4eecff5..0000000 --- a/.coveralls.yml +++ /dev/null @@ -1,3 +0,0 @@ -service_name: travis-ci -coverage_clover: clover.xml -json_path: coveralls-upload.json diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b85b2e4..7bd6293 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -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 diff --git a/.gitignore b/.gitignore index fb27267..3021101 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ /coverage/ /vendor/ /clover.xml +.* composer.lock phpunit.xml +!/.github/ +!.gitattributes diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index 2e54f9a..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,31 +0,0 @@ -filter: - excluded_paths: - - 'vendor/*' -before_commands: - - 'composer install' -build: - nodes: - analysis: - tests: - override: - - php-scrutinizer-run - tests: - override: - - phpcs-run --standard=PSR2 -tools: - php_analyzer: true - php_mess_detector: true - php_code_sniffer: - config: - standard: PSR2 - sensiolabs_security_checker: true - php_loc: - excluded_dirs: - - vendor - php_pdepend: true - php_sim: true -build_failure_conditions: - - 'elements.rating(<= D).new.exists' - - 'issues.label("coding-style").new.exists' - - 'issues.severity(>= MAJOR).new.exists' - - 'project.metric("scrutinizer.quality", < 8)' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 36bdffb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,18 +0,0 @@ -sudo: false -language: php -php: - - 7.0 - - 7.1 - - 7.2 - - nightly -env: - - PREFER_LOWEST="--prefer-lowest --prefer-stable" - - PREFER_LOWEST="" -matrix: - fast_finish: true - allow_failures: - - php: nightly -before_script: - - composer update $PREFER_LOWEST -script: ./vendor/bin/phpunit --coverage-clover clover.xml -after_success: ./vendor/bin/coveralls -v diff --git a/composer.json b/composer.json index ee3361f..6d6bd0c 100644 --- a/composer.json +++ b/composer.json @@ -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 diff --git a/src/Util/Http.php b/src/Util/Http.php index f839373..41edcf7 100644 --- a/src/Util/Http.php +++ b/src/Util/Http.php @@ -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 []; } @@ -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]); @@ -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 []; } @@ -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); diff --git a/tests/Util/HttpTest.php b/tests/Util/HttpTest.php index 930880b..f083116 100644 --- a/tests/Util/HttpTest.php +++ b/tests/Util/HttpTest.php @@ -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 @@ -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'], + ], + ]; + } }