Skip to content

Commit

Permalink
Add url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathieu Ferment committed Sep 30, 2014
1 parent fda1594 commit 502f650
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions explore_url.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ function validateInput($argv)
$isValid = true;
}

if (!filter_var($argv[1], FILTER_VALIDATE_URL)) {
echo 'Bad url: ' . $argv[1] . PHP_EOL;
die(1);
}

if (!$isValid) {
echo 'php explore_url <url> [--urldecode]' . PHP_EOL;
die(1);
Expand All @@ -47,13 +52,10 @@ function validateInput($argv)
$GETParts = explode('&', $url);
$pathParts = explode('?', $GETParts[0]);

if (count($pathParts) !== 2) {
throw new Exception('Not a valid url : found more than 1 ?');
}

$path = $pathParts[0];
$firstParameter = $pathParts[1];
$parameters = array_slice($GETParts, 1);
$moreParameters = array_slice($GETParts, 1);
$parameters = array_merge(array($firstParameter), $moreParameters);

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

// echo GET parameters
echo echoParameter($firstParameter, $urldecode);
foreach ($parameters as $parameter) {
echoParameter($parameter, $urldecode);
}

0 comments on commit 502f650

Please sign in to comment.