Small cleanup using static analysis

This commit is contained in:
HairyFotr
2014-05-31 00:51:25 +02:00
parent 1e8224536b
commit 7698f12112
14 changed files with 24 additions and 26 deletions

View File

@@ -59,7 +59,7 @@ trait IndexControllerBase extends ControllerBase {
updateLastLoginDate(account.userName)
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
if(redirectUrl.replaceFirst("/$", "") == request.getContextPath){
if(redirectUrl.stripSuffix("/") == request.getContextPath){
redirect("/")
} else {
redirect(redirectUrl)

View File

@@ -53,7 +53,7 @@ trait LabelsControllerBase extends ControllerBase {
*/
private def labelName: Constraint = new Constraint(){
override def validate(name: String, value: String, messages: Messages): Option[String] =
if(!value.matches("^[^,]+$")){
if(value.contains(',')){
Some(s"${name} contains invalid character.")
} else if(value.startsWith("_") || value.startsWith("-")){
Some(s"${name} starts with invalid character.")
@@ -62,4 +62,4 @@ trait LabelsControllerBase extends ControllerBase {
}
}
}
}

View File

@@ -255,7 +255,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
val name = multiParams("splat").head
if(name.endsWith(".zip")){
val revision = name.replaceFirst("\\.zip$", "")
val revision = name.stripSuffix(".zip")
val workDir = getDownloadWorkDir(repository.owner, repository.name, session.getId)
if(workDir.exists){
FileUtils.deleteDirectory(workDir)
@@ -316,9 +316,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
case branch if(path == branch || path.startsWith(branch + "/")) => branch
} orElse repository.tags.collectFirst {
case tag if(path == tag.name || path.startsWith(tag.name + "/")) => tag.name
} orElse Some(path.split("/")(0)) get
} getOrElse path.split("/")(0)
(id, path.substring(id.length).replaceFirst("^/", ""))
(id, path.substring(id.length).stripPrefix("/"))
}