Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 502f650

Browse files
author
Mathieu Ferment
committed
Add url validation
1 parent fda1594 commit 502f650

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

‎explore_url.php‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ function validateInput($argv)
3232
$isValid = true;
3333
}
3434

35+
if (!filter_var($argv[1], FILTER_VALIDATE_URL)) {
36+
echo 'Bad url: ' . $argv[1] . PHP_EOL;
37+
die(1);
38+
}
39+
3540
if (!$isValid) {
3641
echo 'php explore_url <url> [--urldecode]' . PHP_EOL;
3742
die(1);
@@ -47,13 +52,10 @@ function validateInput($argv)
4752
$GETParts = explode('&', $url);
4853
$pathParts = explode('?', $GETParts[0]);
4954

50-
if (count($pathParts) !== 2) {
51-
throw new Exception('Not a valid url : found more than 1 ?');
52-
}
53-
5455
$path = $pathParts[0];
5556
$firstParameter = $pathParts[1];
56-
$parameters = array_slice($GETParts, 1);
57+
$moreParameters = array_slice($GETParts, 1);
58+
$parameters = array_merge(array($firstParameter), $moreParameters);
5759

5860
// echo result
5961
echo TextColorWriter::textColor('URL ANALYSIS:', TextColorWriter::BASH_PROMPT_GREEN) . PHP_EOL;
@@ -63,7 +65,6 @@ function validateInput($argv)
6365
$urldecode = isset($argv[2]);
6466

6567
// echo GET parameters
66-
echo echoParameter($firstParameter, $urldecode);
6768
foreach ($parameters as $parameter) {
6869
echoParameter($parameter, $urldecode);
6970
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /