@@ -20,9 +20,56 @@ private object Rfc3986CharSets {
2020 val regName = unreserved + pctEncoded + subDelims
2121}
2222
23+ /* *
24+ * Determines if the given region is valid for the purposes of endpoint lookup, specifically that the region is suitable
25+ * to use in a URI hostname according to [RFC 3986 § 3.2.2](https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2).
26+ *
27+ * Valid characters for regions include:
28+ * * URI unreserved characters:
29+ * * Uppercase letters (`A` through `Z`)
30+ * * Lowercase letters (`a` through `z`)
31+ * * Digits (`0` through `9`)
32+ * * Hyphen (`-`)
33+ * * Period/dot (`.`)
34+ * * Tilde (`~`)
35+ * * Underscore (`_`)
36+ * * Percent (`%`)
37+ * * URI sub-delimiters
38+ * * Ampersand (`&`)
39+ * * Apostrophe (`'`)
40+ * * Asterisk (`*`)
41+ * * Comma (`,`)
42+ * * Dollar sign (`$`)
43+ * * Equals sign (`=`)
44+ * * Exclamation point (`!`)
45+ * * Parentheses (`(` and `)`)
46+ * * Plus (`+`)
47+ * * Semicolon (`;`)
48+ *
49+ * Notable characters which are _invalid_ for regions include:
50+ * * Space (` `)
51+ * * At sign (`@`)
52+ * * Backtick/grave (`` ` ``)
53+ * * Braces (`{` and `}`)
54+ * * Brackets (`[` and `]`)
55+ * * Caret (`^`)
56+ * * Colon (`:`)
57+ * * Double quote (`"`)
58+ * * Hash/number sign (`#`)
59+ * * Inequality signs (`<` and `>`)
60+ * * Pipe (`|`)
61+ * * Question mark (`?`)
62+ * * Slashes (`/` and `\`)
63+ * * All non-ASCII characters (e.g., Unicode characters)
64+ */
2365@InternalSdkApi
2466public fun isRegionValid (region : String ): Boolean = region.isNotEmpty() && region.all(Rfc3986CharSets .regName::contains)
2567
68+ /* *
69+ * Validates that a region is suitable to use in a URI hostname according to
70+ * [RFC 3986 § 3.2.2](https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2). See [isRegionValid] for a detailed
71+ * description of the validation criteria.
72+ */
2673@InternalSdkApi
2774public fun validateRegion (region : String ): String = region.also {
2875 if (! isRegionValid(region)) {
0 commit comments