Skip to content

Commit

Permalink
Fix an issue with Texts.format causing text loss
Browse files Browse the repository at this point in the history
Elements seen prior to a placeholder element would be dropped,
stripping out the beginning of some texts.
  • Loading branch information
zml2008 committed Aug 15, 2015
1 parent fb09f11 commit c4ca8b5
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/main/java/org/spongepowered/api/text/Texts.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.api.text;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkElementIndex;
import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.base.Optional;
Expand Down Expand Up @@ -309,14 +310,16 @@ private static Text formatNoChecks(Text template, Map<String, ?> replacements) {
}
// Also check child texts for placeholders
TextBuilder builder = null;
for (Text child : template.getChildren()) {
List<Text> children = template.getChildren();
for (int i = 0; i < children.size(); ++i) {
final Text child = children.get(i);
Text formatted = formatNoChecks(child, replacements);
if (builder == null) {
if (formatted == child) {
continue;
}
builder = template.builder();
builder.removeAll();
builder.remove(children.subList(i, children.size()));
}
builder.append(formatted);
}
Expand Down

0 comments on commit c4ca8b5

Please sign in to comment.