Fix validation for user name, page name and repository name.

This commit is contained in:
takezoe
2013-06-21 18:56:00 +09:00
parent b20f85e21c
commit 4d4e0c8487
5 changed files with 26 additions and 55 deletions

View File

@@ -34,6 +34,17 @@ abstract class ControllerBase extends ScalatraFilter with ClientSideValidationFo
url.substring(0, url.length - request.getRequestURI.length)
}
protected def identifier: Constraint = new Constraint(){
def validate(name: String, value: String): Option[String] =
if(!value.matches("^[a-zA-Z0-9\\-_]+$")){
Some("%s contains invalid character.".format(name))
} else if(value.startsWith("_") || value.startsWith("-")){
Some("%s starts with invalid character.".format(name))
} else {
None
}
}
}
case class Context(path: String, loginAccount: Option[Account])