Skip to content

Commit 1292cca

Browse files
committed
Don't modify the original PatternElements
1 parent 0325bb2 commit 1292cca

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

fluent.syntax/src/main/kotlin/org/projectfluent/syntax/processor/Processor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class Processor {
3737
when (element) {
3838
is TextElement -> {
3939
if (lastText == null) {
40-
lastText = element
40+
lastText = TextElement(element.value)
4141
} else {
4242
lastText?.let { it.value += element.value }
4343
}

fluent.syntax/src/test/kotlin/org/projectfluent/syntax/processor/ProcessorTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,26 @@ internal class ProcessorTest {
3232
processor.unescapeLiteralsToText(pattern)
3333
)
3434

35+
pattern.elements.clear()
36+
pattern.elements.addAll(
37+
arrayOf(
38+
TextElement("Foo "),
39+
Placeable(expression = StringLiteral("Bar"))
40+
)
41+
)
42+
assertEquals(
43+
Pattern(TextElement("Foo Bar")),
44+
processor.unescapeLiteralsToText(pattern)
45+
)
46+
// The original Pattern isn't modified.
47+
assertEquals(
48+
Pattern(
49+
TextElement("Foo "),
50+
Placeable(expression = StringLiteral("Bar"))
51+
),
52+
pattern
53+
)
54+
3555
pattern.elements.clear()
3656
pattern.elements.addAll(
3757
arrayOf(

0 commit comments

Comments
 (0)