Skip to content

Commit a24f8fd

Browse files
committed
Merge branch 'master' of https://github.com/WebFiori/http
2 parents 72a6fb8 + 7d91f5a commit a24f8fd

7 files changed

Lines changed: 135 additions & 26 deletions

File tree

.github/workflows/php7.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Build PHP 7
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
os: [ ubuntu-latest ]
16+
php: [7.1, 7.0, 5.6]
17+
18+
name: PHP${{matrix.php}} - ${{matrix.os}}
19+
20+
steps:
21+
- name: Clone Repo
22+
uses: actions/checkout@v1
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: mysqli, mbstring
29+
tools: phpunit:5.7.27, composer
30+
31+
- name: Install Dependencies
32+
run: composer install --prefer-source --no-interaction --no-dev
33+
34+
- name: Execute Tests
35+
run: phpunit

.github/workflows/php8.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build PHP 7,8
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
test:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
os: [ ubuntu-latest ]
16+
php: [ 8.0, 7.4, 7.3, 7.2]
17+
18+
name: PHP${{matrix.php}} - ${{matrix.os}}
19+
20+
steps:
21+
- name: Clone Repo
22+
uses: actions/checkout@v1
23+
24+
- name: Setup PHP
25+
uses: shivammathur/setup-php@v2
26+
with:
27+
php-version: ${{ matrix.php }}
28+
extensions: mysqli, mbstring
29+
tools: phpunit:8.5.13, composer
30+
31+
- name: Install Dependencies
32+
run: composer install --prefer-source --no-interaction --no-dev
33+
34+
- name: Execute Tests
35+
run: phpunit
36+
37+
- name: CodeCov
38+
uses: codecov/codecov-action@v1
39+
40+
- name: SonarCloud
41+
uses: SonarSource/sonarcloud-github-action@master
42+
env:
43+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
45+
46+

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ A simple library for creating RESTful web APIs in aadition to providing the deve
33
It includes inputs feltering and data validation in addion to creating user-defined inputs filters.
44

55
<p align="center">
6-
<a href="https://travis-ci.com/github/WebFiori/http">
7-
<img src="https://travis-ci.com/WebFiori/http.svg?branch=master">
6+
<a href="https://github.com/WebFiori/http/actions">
7+
<img src="https://github.com/WebFiori/http/workflows/Build%20PHP%207,8/badge.svg?branch=master">
88
</a>
99
<a href="https://codecov.io/gh/WebFiori/http">
1010
<img src="https://codecov.io/gh/WebFiori/http/branch/master/graph/badge.svg" />

src/APIFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ public static function filter(APIFilter $apiFilter, array $arr) {
189189
$defaultVal = $def[$paramIdx]->getDefault();
190190

191191
if (isset($arr[$name])) {
192-
$toBeFiltered = $arr[$name];
193-
$retVal[$noFIdx][$name] = $arr[$name];
192+
$toBeFiltered = urldecode($arr[$name]);
193+
$retVal[$noFIdx][$name] = $toBeFiltered;
194194

195195
if (isset($def[$optIdx]['filter-func'])) {
196196
$retVal[$filteredIdx][$name] = self::_applyCustomFilterFunc($def, $toBeFiltered);

src/Uri.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,12 @@ public static function splitURI($uri) {
601601
],
602602
];
603603
//First step, extract the fragment
604-
$split1 = explode('#', $uri);
604+
$split1 = self::_queryOrFragment($uri, '#', '%23');
605605
$retVal['fragment'] = isset($split1[1]) ? $split1[1] : '';
606606

607607
//after that, extract the query string
608-
$split2 = explode('?', $split1[0]);
608+
$split2 = self::_queryOrFragment($split1[0], '?', '%3F');
609+
609610
$retVal['query-string'] = isset($split2[1]) ? $split2[1] : '';
610611

611612
//next comes the scheme
@@ -651,6 +652,28 @@ public static function splitURI($uri) {
651652

652653
return $retVal;
653654
}
655+
private static function _queryOrFragment($split, $char, $encoded) {
656+
$split2 = explode($char, $split);
657+
$spCount = count($split2);
658+
if ($spCount > 2) {
659+
$temp = [];
660+
for ($x = 0 ; $x < $spCount - 1 ; $x++) {
661+
$temp[] = $split2[$x];
662+
}
663+
$lastStr = $split2[$spCount - 1];
664+
if (strlen($lastStr) == 0) {
665+
$split2 = [
666+
implode($encoded, $temp).$encoded
667+
];
668+
} else {
669+
$split2 = [
670+
implode($encoded, $temp),
671+
$split2[$spCount - 1]
672+
];
673+
}
674+
}
675+
return $split2;
676+
}
654677
/**
655678
* Validate the path part of original URI and the requested one.
656679
*

tests/UriTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,29 @@ public function testSplitURI_08() {
186186
$uriObj = new Uri($uri, '');
187187
$this->assertEquals('/Hello World',$uriObj->getPath());
188188
}
189+
/**
190+
* @test
191+
*/
192+
public function testSplitURI_09() {
193+
$uri = 'https://programmingacademia.com/Hello World? or Not?';
194+
$uriObj = new Uri($uri, '');
195+
$this->assertEquals('/Hello World? or Not?',$uriObj->getPath());
196+
}
197+
/**
198+
* @test
199+
*/
200+
public function testSplitURI_10() {
201+
$uri = 'https://programmingacademia.com/Hello World? or Not?Yes';
202+
$uriObj = new Uri($uri, '');
203+
$this->assertEquals('/Hello World? or Not',$uriObj->getPath());
204+
}
205+
/**
206+
* @test
207+
*/
208+
public function testSplitURI_11() {
209+
$uri = 'https://programmingacademia.com/Hello World#or Not#Yes';
210+
$uriObj = new Uri($uri, '');
211+
$this->assertEquals('/Hello World#or Not',$uriObj->getPath());
212+
$this->assertEquals('Yes',$uriObj->getFragment());
213+
}
189214
}

0 commit comments

Comments
 (0)