Skip to content

Commit e0e613c

Browse files
committedOct 5, 2023
Limit escaping to & char
1 parent de82c41 commit e0e613c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed
 

‎src/commonMain/kotlin/stream.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ internal fun Appendable.escapeAppend(value: CharSequence) {
191191
while (currentIndex < value.length) {
192192
val code = value[currentIndex].code
193193

194-
if (code == '\\'.code) {
194+
if (code == '\\'.code && currentIndex + 1 < value.length && value[currentIndex + 1] == '&') {
195195
append(value.substring(lastIndex, currentIndex))
196196
check(currentIndex + 1 < value.length) { "String must not end with '\\'." }
197197
append(value[currentIndex + 1])

‎src/commonTest/kotlin/EscapeAppendTest.kt

+11-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class EscapeAppendTest {
77
@Test
88
fun testAppendEscaped() {
99
assertEquals("&", escape("\\&"))
10-
assertEquals("a", escape("\\a"))
10+
assertEquals("\\a", escape("\\a"))
1111
}
1212

1313
@Test
@@ -25,6 +25,16 @@ class EscapeAppendTest {
2525
assertEquals("&&amp;", escape("\\&&"))
2626
assertEquals("&amp;", escape("\\&amp;"))
2727
}
28+
29+
@Test
30+
fun testEscapeSlash() {
31+
assertEquals("\\", escape("\\"))
32+
}
33+
34+
@Test
35+
fun testEscapeUnicode() {
36+
assertEquals("\\u003d", escape("\\u003d"))
37+
}
2838
}
2939

3040
private fun escape(string: String): String = buildString {

0 commit comments

Comments
 (0)
Please sign in to comment.