Skip to content

Commit a32deb8

Browse files
authored
Merge pull request #303 from Kotlin/escaping-backslash-html
[Bug fix] "SyntaxError: Invalid hexadecimal escape sequence" for rendering DataFrames with "\" in content
2 parents 5263fb9 + 1c0f5a8 commit a32deb8

File tree

2 files changed

+8
-1
lines changed
  • core/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/io
    • test/kotlin/org/jetbrains/kotlinx/dataframe/rendering

2 files changed

+8
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/html.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ internal fun String.escapeHTML(): String {
261261
val str = this
262262
return buildString {
263263
for (c in str) {
264-
if (c.code > 127 || c == '"' || c == '\'' || c == '<' || c == '>' || c == '&') {
264+
if (c.code > 127 || c == '"' || c == '\'' || c == '<' || c == '>' || c == '&' || c == '\\') {
265265
append("&#")
266266
append(c.code)
267267
append(';')

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/rendering/RenderingTests.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ class RenderingTests {
5656
html shouldContain "&#60;Air France&#62;"
5757
}
5858

59+
@Test
60+
fun unicodeEscapeSequencesAreEscaped() {
61+
val df = dataFrameOf("content")("""Hello\nfrom \x and \y""")
62+
val html = df.toHTML().toString()
63+
html shouldContain "Hello&#92;nfrom &#92;x and &#92;y"
64+
}
65+
5966
@Test
6067
fun `long text is trimmed without escaping`() {
6168
val df = dataFrameOf("text")("asdfkjasdlkjfhasljkddasdasdasdasdasdasdhf")

0 commit comments

Comments
 (0)