Skip to content

Commit 3a3ca30

Browse files
committed
Merge branch 'fix-backslash-in-texts' into 'master'
[FIX][SDK] fixed backslashes being incorrectly parsed for Texts See merge request codingame/game-engine!318
2 parents 78e3cc0 + 084c0bc commit 3a3ca30

File tree

4 files changed

+29
-19
lines changed

4 files changed

+29
-19
lines changed

engine/modules/entities/src/main/java/com/codingame/gameengine/module/entities/Serializer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ static String formatFrameTime(double t) {
150150
}
151151

152152
static String escape(String text) {
153-
String escaped = text.replaceAll("\\'", "\\\\'");
154-
if (escaped.contains(" ") || escaped.contains(";") || escaped.contains("\n")) {
153+
if (text.contains(" ") || text.contains(";") || text.contains("\n") || text.contains("'")) {
154+
String escaped = text.replaceAll("\\'", "\\\\'");
155155
return "'" + escaped + "'";
156156
}
157-
return escaped;
157+
return text;
158158
}
159159

160160
private String serializeEntitiesStateDiff(Entity<?> entity, EntityState diff, String frameInstant) {

engine/modules/entities/src/main/resources/view/entity-module/CommandParser.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,37 @@ function splitOnCharOutsideQuotes (text, charParam) {
1010
const res = []
1111
let current = ''
1212
let idx = 0
13-
let lastChar = ''
13+
let isEscaped = false
1414
let inQuotes = false
1515

16+
1617
while (idx < text.length) {
1718
const char = text[idx++]
1819
if (char === charParam) {
1920
if (!inQuotes) {
2021
res.push(current)
2122
current = ''
2223
} else {
24+
if (isEscaped) {
25+
current += '\\'
26+
isEscaped = false
27+
}
2328
current += char
2429
}
25-
} else if (char === "'" && lastChar !== '\\') {
30+
} else if (char === "'" && !isEscaped) {
2631
inQuotes = !inQuotes
2732
current += char
28-
} else if (lastChar === '\\') {
29-
if (char === "'") {
30-
current += "\\'"
31-
} else {
33+
} else if (isEscaped) {
3234
current += '\\' + char
33-
}
34-
} else if (char !== '\\') {
35+
isEscaped = false
36+
} else if (!isEscaped && char === '\\') {
37+
isEscaped = true
38+
} else {
3539
current += char
3640
}
37-
lastChar = char
41+
}
42+
if (isEscaped) {
43+
current += '\\'
3844
}
3945
res.push(current)
4046
return res

engine/modules/entities/src/main/resources/view/entity-module/properties.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,10 @@ export const PROPERTIES = {
153153
}
154154

155155
function unescape (text) {
156-
// replace \' by '
157-
const unescaped = text.split("\\'").join("'")
158-
159-
if (unescaped.includes(' ') || unescaped.includes(';') || unescaped.includes('\n')) {
160-
return unescaped.slice(1, unescaped.length - 1)
161-
} else {
162-
return unescaped
156+
if (text.length >= 2 && text[0] === "'" && text[text.length - 1] === "'") {
157+
const unescaped = text.slice(1, text.length - 1)
158+
// replace \' by '
159+
return unescaped.split("\\'").join("'")
163160
}
161+
return text
164162
}

playground/misc/misc-3-release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## 4.4.4
6+
7+
### 🐞 Bug fix
8+
9+
- Fixed `Text` not displaying or duplicating backslash characters in the viewer
10+
511
## 4.4.3
612

713
### 🐞 Bug fix

0 commit comments

Comments
 (0)