Skip to content

Commit 07a8202

Browse files
committed
Forbid empty strings in month and day-of-week names and AM/PM markers
1 parent 04adf84 commit 07a8202

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

core/common/src/format/DateTimeFormatBuilder.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ public sealed interface DateTimeFormatBuilder {
129129
*
130130
* [am] is used for the AM marker (0-11 hours), [pm] is used for the PM marker (12-23 hours).
131131
*
132+
* Empty strings can not be used as markers.
133+
*
132134
* @see [amPmHour]
133135
*/
134136
public fun amPmMarker(am: String, pm: String)

core/common/src/format/LocalDateFormat.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import kotlinx.datetime.internal.format.parser.Copyable
1212

1313
/**
1414
* A description of how month names are formatted.
15+
*
16+
* An empty string can not be a month name.
1517
*/
1618
public class MonthNames(
1719
/**
@@ -21,6 +23,7 @@ public class MonthNames(
2123
) {
2224
init {
2325
require(names.size == 12) { "Month names must contain exactly 12 elements" }
26+
names.forEach { require(it.isNotEmpty()) { "A month name can not be empty" } }
2427
}
2528

2629
/**
@@ -63,6 +66,8 @@ internal fun MonthNames.toKotlinCode(): String = when (this.names) {
6366

6467
/**
6568
* A description of how day of week names are formatted.
69+
*
70+
* An empty string can not be a day-of-week name.
6671
*/
6772
public class DayOfWeekNames(
6873
/**
@@ -72,6 +77,7 @@ public class DayOfWeekNames(
7277
) {
7378
init {
7479
require(names.size == 7) { "Day of week names must contain exactly 7 elements" }
80+
names.forEach { require(it.isNotEmpty()) { "A month name can not be empty" } }
7581
}
7682

7783
/**

core/common/src/internal/format/parser/ParserOperation.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ internal class StringSetParserOperation<Output>(
152152

153153
init {
154154
for (string in strings) {
155+
require(string.isNotEmpty()) { "Found an empty string in $whatThisExpects" }
155156
var node = trie
156157
for (char in string) {
157158
val searchResult = node.children.binarySearchBy(char.toString()) { it.first }

0 commit comments

Comments
 (0)