File tree Expand file tree Collapse file tree 2 files changed +36
-7
lines changed
main/kotlin/org/projectfluent/syntax/processor
test/kotlin/org/projectfluent/syntax/processor Expand file tree Collapse file tree 2 files changed +36
-7
lines changed Original file line number Diff line number Diff line change 1
1
package org.projectfluent.syntax.processor
2
2
3
3
import org.projectfluent.syntax.ast.* // ktlint-disable no-wildcard-imports
4
- import java.lang.Exception
5
4
import java.lang.StringBuilder
6
5
7
6
/* *
@@ -161,21 +160,27 @@ class Processor {
161
160
if (uni4 != " " ) {
162
161
val codepoint = uni4.substring(1 ).toInt(16 )
163
162
if (Character .isBmpCodePoint(codepoint)) {
164
- return codepoint.toChar().toString()
163
+ val char = codepoint.toChar()
164
+ if (! Character .isSurrogate(char)) {
165
+ return char.toString()
166
+ }
165
167
}
166
168
}
167
169
168
170
val uni6 = matches.next()
169
171
if (uni6 != " " ) {
170
172
val codepoint = uni6.substring(1 ).toInt(16 )
171
173
if (Character .isValidCodePoint(codepoint)) {
172
- val builder = StringBuilder ()
173
- builder.append(Character .highSurrogate(codepoint))
174
- builder.append(Character .lowSurrogate(codepoint))
175
- return builder
174
+ val char = codepoint.toChar()
175
+ if (! Character .isSurrogate(char)) {
176
+ val builder = StringBuilder ()
177
+ builder.append(Character .highSurrogate(codepoint))
178
+ builder.append(Character .lowSurrogate(codepoint))
179
+ return builder
180
+ }
176
181
}
177
182
}
178
183
179
- throw Exception ( " Unexpected " )
184
+ return " � "
180
185
}
181
186
}
Original file line number Diff line number Diff line change @@ -81,6 +81,30 @@ internal class ProcessorTest {
81
81
processor.unescapeLiteralsToText(pattern)
82
82
)
83
83
84
+ pattern.elements.clear()
85
+ pattern.elements.addAll(
86
+ arrayOf(
87
+ TextElement (" Illegal escape sequence: " ),
88
+ Placeable (expression = StringLiteral (""" \ud800""" ))
89
+ )
90
+ )
91
+ assertEquals(
92
+ Pattern (TextElement (" Illegal escape sequence: �" )),
93
+ processor.unescapeLiteralsToText(pattern)
94
+ )
95
+
96
+ pattern.elements.clear()
97
+ pattern.elements.addAll(
98
+ arrayOf(
99
+ TextElement (" Illegal escape sequence: " ),
100
+ Placeable (expression = StringLiteral (""" \U00d800""" ))
101
+ )
102
+ )
103
+ assertEquals(
104
+ Pattern (TextElement (" Illegal escape sequence: �" )),
105
+ processor.unescapeLiteralsToText(pattern)
106
+ )
107
+
84
108
pattern.elements.clear()
85
109
pattern.elements.addAll(
86
110
arrayOf(
You can’t perform that action at this time.
0 commit comments