import java.time.Clock;
import java.util.Objects;
+import kotlinx.html.DIV;
import net.pterodactylus.rhynodge.Reaction;
import net.pterodactylus.rhynodge.State;
import net.pterodactylus.rhynodge.output.DefaultOutput;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
-import com.google.common.escape.Escaper;
-import com.google.common.html.HtmlEscapers;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
+import static java.util.Collections.emptyMap;
+import static kotlinx.html.stream.StreamKt.createHTML;
+
/**
* Abstract implementation of a {@link State} that knows about the basic
* attributes of a {@link State}.
@Nullable
protected String htmlText() {
- //noinspection UnstableApiUsage
- return "<div>" + htmlEscaper.escape(plainText()) + "</div>";
+ var tagConsumer = createHTML(false, false);
+ var div = new DIV(emptyMap(), tagConsumer);
+ div.text(plainText());
+ return tagConsumer.finalize();
}
- @SuppressWarnings("UnstableApiUsage")
- private static final Escaper htmlEscaper = HtmlEscapers.htmlEscaper();
-
@Override
public int hashCode() {
return Objects.hash(success, empty, time, failCount, exception);
assertThat(first.equals(second), equalTo(false))
}
+ @Test
+ fun `state encodes html text correctly`() {
+ val state = object : AbstractState() {
+ override fun plainText() = "a & b"
+ }
+ assertThat(state.htmlText(), equalTo("a & b"))
+ }
+
}
private val testClock = Clock.fixed(now(), UTC)