Permalink
Browse files

Make URL validation patterns case-insensitive

Fixes #147
  • Loading branch information...
bojidar-bg committed Jun 3, 2018
1 parent 893293a commit c491c2be6f06e0f22444684c53815e99c5d23f44
Showing with 8 additions and 8 deletions.
  1. +7 −7 src/Helpers/Utils.php
  2. +1 −1 src/routes/asset_edit.php
@@ -21,36 +21,36 @@ public function getComputedDownloadUrl($repo_url, $provider, $commit, &$warning=
$light_warning_suffix = "Please, doublecheck that the URL and the repository provider are correct.";
switch ($provider) {
case 'GitHub':
if (sizeof(preg_grep('/^https:\/\/github\.com\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
if (sizeof(preg_grep('/^https:\/\/github\.com\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https://github.com/<owner>/<name>\". $warning_suffix\n";
}
return "$repo_url/archive/$commit.zip";
case 'GitLab':
if (sizeof(preg_grep('/^https:\/\/(gitlab\.com|[^\/]+)\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
if (sizeof(preg_grep('/^https:\/\/(gitlab\.com|[^\/]+)\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https://<gitlab instance>/<owner>/<name>\". $warning_suffix\n";
} elseif (sizeof(preg_grep('/^https:\/\/(gitlab\.com)\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
} elseif (sizeof(preg_grep('/^https:\/\/(gitlab\.com)\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" might not be correct; it should be similar to \"https://gitlab.com/<owner>/<name>\", unless the asset is hosted on a custom instance of GitLab. $light_warning_suffix\n";
}
return "$repo_url/repository/archive.zip?ref=$commit";
case 'BitBucket':
if (sizeof(preg_grep('/^https:\/\/bitbucket\.org\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
if (sizeof(preg_grep('/^https:\/\/bitbucket\.org\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"https://bitbucket.org/<owner>/<name>\". $warning_suffix\n";
}
return "$repo_url/get/$commit.zip";
case 'Gogs':
if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"http<s>://<gogs instance>/<owner>/<name>\". $warning_suffix\n";
}
$warning .= "Since Gogs might be self-hosted, we can't be sure that \"$repo_url\" is a valid Gogs URL. $light_warning_suffix\n";
return "$repo_url/archive/$commit.zip";
case 'cgit':
if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/', [$repo_url])) == 0) {
if (sizeof(preg_grep('/^https?:\/\/[^\/]+?\/[^\/]+?\/[^\/]+?$/i', [$repo_url])) == 0) {
$warning .= "\"$repo_url\" doesn't look correct; it should be similar to \"http<s>://<cgit instance>/<owner>/<name>\". $warning_suffix\n";
}
$warning .= "Since cgit might be self-hosted, we can't be sure that \"$repo_url\" is a valid cgit URL. $light_warning_suffix\n";
return "$repo_url/snapshot/$commit.zip";
case 'Custom':
if (sizeof(preg_grep('/^https?:\/\/.+?\.zip$/', [$commit])) == 0) {
if (sizeof(preg_grep('/^https?:\/\/.+?\.zip$/i', [$commit])) == 0) {
$warning .= "\"$commit\" doesn't look correct; it should be similar to \"http<s>://<url>.zip\". $warning_suffix\n";
}
return "$commit";
@@ -101,7 +101,7 @@ function _insert_asset_edit_fields($c, $error, &$response, $query, $body, $requi
}
if (isset($body['icon_url'])) {
$icon_url = $body['icon_url'];
if (sizeof(preg_grep('/^https?:\/\/.+?\.(png|jpg|jpeg)$/', [$icon_url])) == 0) {
if (sizeof(preg_grep('/^https?:\/\/.+?\.(png|jpg|jpeg)$/i', [$icon_url])) == 0) {
$warning .= "\"$icon_url\" doesn't look correct; it should be similar to \"http<s>://<url>.<png/jpg>\". Make sure the icon URL is correct.\n";
}
}

0 comments on commit c491c2b

Please sign in to comment.