From 6e0880e6d85128336b86125eac5db94343bf907f Mon Sep 17 00:00:00 2001 From: 6543 <6543@noreply.gitea.io> Date: Sun, 29 Mar 2020 18:57:19 +0000 Subject: [PATCH] Handle reserved names & patterns on repo creation (#315) correct var names working solution code format ... first draft Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/315 Reviewed-by: M M Arif --- .../gitnex/activities/CreateRepoActivity.java | 23 ++++++++++++++----- app/src/main/res/values/strings.xml | 2 ++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/org/mian/gitnex/activities/CreateRepoActivity.java b/app/src/main/java/org/mian/gitnex/activities/CreateRepoActivity.java index 2170cfcd..8739ea64 100644 --- a/app/src/main/java/org/mian/gitnex/activities/CreateRepoActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/CreateRepoActivity.java @@ -25,7 +25,9 @@ import org.mian.gitnex.models.OrganizationRepository; import org.mian.gitnex.util.AppUtil; import org.mian.gitnex.util.TinyDB; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.regex.Pattern; import retrofit2.Call; import retrofit2.Callback; @@ -46,11 +48,15 @@ public class CreateRepoActivity extends BaseActivity { List organizationsList = new ArrayList<>(); + //https://github.com/go-gitea/gitea/blob/52cfd2743c0e85b36081cf80a850e6a5901f1865/models/repo.go#L964-L967 + final List reservedRepoNames = Arrays.asList(".", ".."); + final Pattern reservedRepoPatterns = Pattern.compile("\\.(git|wiki)$"); + @Override protected int getLayoutResourceId(){ return R.layout.activity_new_repo; } - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -105,7 +111,6 @@ public class CreateRepoActivity extends BaseActivity { createRepo.setOnClickListener(createRepoListener); } - } private View.OnClickListener createRepoListener = new View.OnClickListener() { @@ -153,15 +158,23 @@ public class CreateRepoActivity extends BaseActivity { Toasty.info(getApplicationContext(), getString(R.string.repoNameErrorInvalid)); + } + else if (reservedRepoNames.contains(newRepoName)) { + + Toasty.info(getApplicationContext(), getString(R.string.repoNameErrorReservedName)); + + } + else if (reservedRepoPatterns.matcher(newRepoName).find()) { + + Toasty.info(getApplicationContext(), getString(R.string.repoNameErrorReservedPatterns)); + } else { - //Log.i("repoOwner", String.valueOf(repoOwner)); disableProcessButton(); createNewRepository(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), loginUid, newRepoName, newRepoDesc, repoOwner, newRepoAccess); } - } private void createNewRepository(final String instanceUrl, final String token, String loginUid, String repoName, String repoDesc, String repoOwner, boolean isPrivate) { @@ -229,7 +242,6 @@ public class CreateRepoActivity extends BaseActivity { enableProcessButton(); } }); - } private void getOrganizations(String instanceUrl, String instanceToken, final String userLogin) { @@ -304,7 +316,6 @@ public class CreateRepoActivity extends BaseActivity { enableProcessButton(); } }); - } private void initCloseListener() { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6cb0fcc6..a1a10a6e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -102,6 +102,8 @@ Repository name is empty Repository name is not valid. [a–z A–Z 0–9 – _] + Repository name is reserved + Repository name contains reserved keywords Repository description exceeds the max 255 characters limit Repository created successfully Something went wrong, please try again