Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
fix is_a_url function
Browse files Browse the repository at this point in the history
Ref: #750
  • Loading branch information
wellingguzman committed Feb 11, 2019
1 parent bd05cfa commit 81582e1
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/helpers/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,28 @@ function filename_put_ext($name, $ext = null)
*/
function is_a_url($value)
{
return filter_var($value, FILTER_VALIDATE_URL);
if (!is_string($value)) {
return false;
}

if (preg_match('#^data:.+\/.+;base64,#si', $value)) {
return false;
}

// Ported from: https://github.com/segmentio/is-url/blob/master/index.js
if (!preg_match('#^(?:\w+:)?\/\/(.+)$#si', $value, $matches)) {
return false;
}

$hostAndPath = $matches[1];
if (!$hostAndPath) {
return false;
}

if (preg_match('#^[^\s\.]+\.\S{2,}$#si', $hostAndPath)) {
return true;
}

return false;
}
}

0 comments on commit 81582e1

Please sign in to comment.