From c4efb14d7cd1201c57f38af0c3d66e886d768d74 Mon Sep 17 00:00:00 2001 From: scria1000 <91804886+scria1000@users.noreply.github.com> Date: Sat, 11 Mar 2023 04:29:24 +0000 Subject: Prevent superscript crash with empty spoiler (#1387) --- .../markdown/SuperscriptPlugin.java | 36 +++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'app/src') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java index 796ca870..20a56327 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java @@ -142,6 +142,36 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin { if (notEmptyLink((Link) next)) { return true; } + } else if (next instanceof SpoilerNode) { + if (notEmptySpoilerNode((SpoilerNode) next)) { + return true; + } + } else { + return true; + } + next = next.getNext(); + } + + return false; + } + + private boolean notEmptySpoilerNode(SpoilerNode spoilerNode) { + Node next = spoilerNode.getFirstChild(); + while (next != null) { + if (next instanceof Text) { + return true; + } else if (next instanceof Superscript) { + if (notEmptySuperscript((Superscript) next)) { + return true; + } + } else if (next instanceof Link) { + if (notEmptyLink((Link) next)) { + return true; + } + } else if (next instanceof SpoilerNode) { + if (notEmptySpoilerNode((SpoilerNode) next)) { + return true; + } } else { return true; } @@ -154,7 +184,7 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin { private boolean notEmptySuperscript(Superscript superscript) { Node next; if (superscript.isBracketed()) { - next = superscript.getFirstChild(); + next = superscript.getFirstChild(); } else { next = superscript.getNext(); } @@ -164,6 +194,10 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin { if (notEmptyLink((Link) next)) { return true; } + } else if (next instanceof SpoilerNode) { + if (notEmptySpoilerNode((SpoilerNode) next)) { + return true; + } } else if (!(next instanceof Superscript)) { return true; } else { -- cgit v1.2.3