From d85f96256ecf622a581ee663d75e6dd501808f0e Mon Sep 17 00:00:00 2001 From: BOUDJENIBA Oussama <41930319+ouss1002@users.noreply.github.com> Date: Mon, 4 Mar 2024 09:58:29 +0100 Subject: [PATCH] Prevent IndexOutOfBoundsException in equation rendering by checking non-empty 'texsymbol' strings This commit introduces a check before accessing the first character of 'texsymbol' strings in equation rendering, preventing IndexOutOfBoundsException when custom functions names are used which can lead to an empty string. This change ensures that equations custom variables names ending with standard function strings are handled gracefully without errors --- src/net/sourceforge/plantuml/math/ASCIIMathTeXImg.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net/sourceforge/plantuml/math/ASCIIMathTeXImg.java b/src/net/sourceforge/plantuml/math/ASCIIMathTeXImg.java index 6aec5694ca9..7a23f266783 100644 --- a/src/net/sourceforge/plantuml/math/ASCIIMathTeXImg.java +++ b/src/net/sourceforge/plantuml/math/ASCIIMathTeXImg.java @@ -602,7 +602,7 @@ private String[] AMTparseSexpr(String str) { case CONST: str = AMremoveCharsAndBlanks(str, symbol.input.length()); String texsymbol = AMTgetTeXsymbol(symbol); - if (texsymbol.charAt(0) == '\\' || symbol.tag.equals("mo")) + if (texsymbol.isEmpty() || texsymbol.charAt(0) == '\\' || symbol.tag.equals("mo")) return new String[] { texsymbol, str }; else { return new String[] { "{" + texsymbol + "}", str }; @@ -676,7 +676,7 @@ else if (symbol == AMquote) if (result[0] == null) return new String[] { "{" + AMTgetTeXsymbol(symbol) + "}", str }; if (symbol.hasFlag("func")) { // functions hack - st = "" + str.charAt(0); + st = "" + (str.isEmpty() ? "" : str.charAt(0)); if (st.equals("^") || st.equals("_") || st.equals("/") || st.equals("|") || st.equals(",") || (symbol.input.length() == 1 && symbol.input.matches("\\w") && !st.equals("("))) { return new String[] { "{" + AMTgetTeXsymbol(symbol) + "}", str };