diff --git a/src/main/scala/app/LabelsController.scala b/src/main/scala/app/LabelsController.scala index 38f6f54..e01c63e 100644 --- a/src/main/scala/app/LabelsController.scala +++ b/src/main/scala/app/LabelsController.scala @@ -13,12 +13,12 @@ case class LabelForm(labelName: String, color: String) val newForm = mapping( - "newLabelName" -> trim(label("Label name", text(required, identifier, maxlength(100)))), + "newLabelName" -> trim(label("Label name", text(required, labelName, maxlength(100)))), "newColor" -> trim(label("Color", text(required, color))) )(LabelForm.apply) val editForm = mapping( - "editLabelName" -> trim(label("Label name", text(required, identifier, maxlength(100)))), + "editLabelName" -> trim(label("Label name", text(required, labelName, maxlength(100)))), "editColor" -> trim(label("Color", text(required, color))) )(LabelForm.apply) @@ -47,4 +47,18 @@ issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository) }) + /** + * Constraint for the identifier such as user name, repository name or page name. + */ + private def labelName: Constraint = new Constraint(){ + def validate(name: String, value: String): Option[String] = + if(!value.matches("^[^,]+$")){ + Some("%s contains invalid character.".format(name)) + } else if(value.startsWith("_") || value.startsWith("-")){ + Some("%s starts with invalid character.".format(name)) + } else { + None + } + } + } \ No newline at end of file