diff --git a/libraries/stdlib/src/kotlin/text/StringsJVM.kt b/libraries/stdlib/src/kotlin/text/StringsJVM.kt index 8031059ffcd..dfa54c17e63 100644 --- a/libraries/stdlib/src/kotlin/text/StringsJVM.kt +++ b/libraries/stdlib/src/kotlin/text/StringsJVM.kt @@ -131,7 +131,7 @@ public fun String.split(regex: Pattern, limit: Int = 0): List /** * Splits this string around matches of the given regular expression. */ -deprecated("Convert String argument to regex with toRegex or use splitBy instead for literal delimiters. Please note the change of return type.", ReplaceWith("split(regex.toRegex()).toTypedArray()")) +deprecated("Convert String argument to regex with toRegex or use splitBy instead for literal delimiters. Please note the change of return type.", ReplaceWith("split(regex.toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()")) public fun String.split(regex: String): Array = (this as java.lang.String).split(regex) /** diff --git a/libraries/stdlib/test/text/StringJVMTest.kt b/libraries/stdlib/test/text/StringJVMTest.kt index 62c719fb37f..29bee11c35e 100644 --- a/libraries/stdlib/test/text/StringJVMTest.kt +++ b/libraries/stdlib/test/text/StringJVMTest.kt @@ -65,6 +65,9 @@ class StringJVMTest { assertEquals(listOf("ab", "cd", "def", ""), s.split(isDigit)) assertEquals(listOf("ab", "cd", "def3"), s.split(isDigit, 3)) + // deprecation replacement equivalence + assertEquals("\\d".toPattern().split(s).toList(), s.split("\\d".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray().toList()) + fails { s.split(isDigit, -1) }