Skip to content

Commit c2ac634

Browse files
author
duy
committed
Check max output size before displaying
1 parent cce1de2 commit c2ac634

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

modules/symja-evaluator/src/main/java/com/symja/evaluator/OutputForm.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
package com.symja.evaluator;
22

3+
import org.matheclipse.core.basic.Config;
34
import org.matheclipse.core.form.output.OutputFormFactory;
45
import org.matheclipse.core.form.tex.TeXFormFactory;
56
import org.matheclipse.core.interfaces.IExpr;
7+
import org.matheclipse.parser.client.ParserConfig;
68

79
public class OutputForm {
10+
811
public static String toString(IExpr result) {
912
if (result == null) {
1013
return "";
1114
}
1215
try {
13-
OutputFormFactory outputFormFactory = OutputFormFactory.get(true, false);
14-
return outputFormFactory.toString(result);
16+
OutputFormFactory outputFormFactory = OutputFormFactory.get(ParserConfig.PARSER_USE_LOWERCASE_SYMBOLS, false);
17+
String string = outputFormFactory.toString(result);
18+
19+
if (string.length() > Config.MAX_OUTPUT_SIZE) {
20+
return "Max output size " + Config.MAX_OUTPUT_SIZE + " characters exceeded";
21+
}
22+
23+
return string;
1524
} catch (Exception e) {
16-
return "Error";
25+
return "Error: " + e.getMessage();
1726
}
1827
}
1928

@@ -27,9 +36,14 @@ public static String toLatex(IExpr expr) {
2736
if (teXFormFactory.convert(buffer, expr)) {
2837
return buffer.toString();
2938
}
39+
40+
if (buffer.length() > Config.MAX_OUTPUT_SIZE) {
41+
return "Max output size " + Config.MAX_OUTPUT_SIZE + " characters exceeded";
42+
}
43+
3044
return "Error";
3145
} catch (Exception e) {
32-
return "Error";
46+
return "Error: " + e.getMessage();
3347
}
3448
}
3549
}

0 commit comments

Comments
 (0)