Skip to content

Commit 681416a

Browse files
Lucas Leblancckipp01
Lucas Leblanc
authored andcommitted
Add a regex to allow only names with lowercase for custom icons
1 parent c965f67 commit 681416a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

scaladoc/src/dotty/tools/scaladoc/SocialLinks.scala

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ enum SocialLinks(val url: String, val className: String):
88
case Custom(cUrl: String, lightIcon: String, darkIcon: String) extends SocialLinks(cUrl, "custom")
99

1010
object SocialLinks:
11+
val LowercaseNamePattern = "^[a-z]+$".r
12+
1113
def parse(s: String): Either[String, SocialLinks] =
1214
val errorPrefix = s"Social links arg $s is invalid: "
1315
val splitted = s.split("::")
16+
1417
splitted.head match {
1518
case "github" if splitted.size == 2 => Right(Github(splitted(1)))
1619
case "github" => Left(errorPrefix + "For 'github' arg expected one argument: url")
@@ -20,8 +23,8 @@ object SocialLinks:
2023
case "gitter" => Left(errorPrefix + "For 'gitter' arg expected one argument: url")
2124
case "discord" if splitted.size == 2 => Right(Discord(splitted(1)))
2225
case "discord" => Left(errorPrefix + "For 'discord' arg expected one argument: url")
23-
case "custom" if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3)))
24-
case "custom" if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2)))
25-
case "custom" => Left(errorPrefix + "For 'custom' arg expected three arguments: url, white icon name, black icon name")
26+
case LowercaseNamePattern() if splitted.size == 4 => Right(Custom(splitted(1), splitted(2), splitted(3)))
27+
case LowercaseNamePattern() if splitted.size == 3 => Right(Custom(splitted(1), splitted(2), splitted(2)))
28+
case LowercaseNamePattern() => Left(errorPrefix + "For 'custom' two minimum arguments are expected: url, white icon name, [dark icon name]")
2629
case _ => Left(errorPrefix)
2730
}

0 commit comments

Comments
 (0)