From c7506452186874523b6e6ddf5c5b26284735b604 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Sat, 5 Oct 2024 17:33:10 +0200 Subject: [PATCH 1/2] Fix StringWrap with strings mixed with long words interspersed with newlines --- .../src/main/java/org/apache/jorphan/util/StringWrap.java | 2 +- .../src/test/java/org/apache/jorphan/util/StringWrapTest.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jorphan/src/main/java/org/apache/jorphan/util/StringWrap.java b/src/jorphan/src/main/java/org/apache/jorphan/util/StringWrap.java index b36f66ad490..d01098bca38 100644 --- a/src/jorphan/src/main/java/org/apache/jorphan/util/StringWrap.java +++ b/src/jorphan/src/main/java/org/apache/jorphan/util/StringWrap.java @@ -126,7 +126,7 @@ public String wrap(String input, String delimiter) { } // Try adding the next line if it does not exceed maxWrap int next = nextLineSeparator; - if (next != -1 && pos - next <= maxWrap) { + if (next != -1 && next - pos <= maxWrap) { // The existing lines do not exceed maxWrap, just reuse them next++; // include newline sb.append(input, pos, next); diff --git a/src/jorphan/src/test/java/org/apache/jorphan/util/StringWrapTest.java b/src/jorphan/src/test/java/org/apache/jorphan/util/StringWrapTest.java index 12b19e3809b..85fd305ca54 100644 --- a/src/jorphan/src/test/java/org/apache/jorphan/util/StringWrapTest.java +++ b/src/jorphan/src/test/java/org/apache/jorphan/util/StringWrapTest.java @@ -29,6 +29,7 @@ public class StringWrapTest { static Stream data() { return Stream.of( + arguments(2, 3, "a\nab\nabc\nabcd\nabcde", "a\nab\nabc\nabc|d\nabc|de"), arguments(2, 2, "0123456789", "01|23|45|67|89"), arguments(2, 5, "0123456789", "01234|56789"), arguments(3, 3, "0123456789", "012|345|678|9"), From f97d6cd78ca981e5a5ca959ac34cf1ba4f819aa2 Mon Sep 17 00:00:00 2001 From: Felix Schumacher Date: Sat, 5 Oct 2024 17:33:48 +0200 Subject: [PATCH 2/2] Guard all JSyntaxArea objects against log text without linebreaks --- .../jmeter/gui/util/JSyntaxTextArea.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java index 6625fa75777..3687639110f 100644 --- a/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java +++ b/src/core/src/main/java/org/apache/jmeter/gui/util/JSyntaxTextArea.java @@ -34,6 +34,7 @@ import org.apache.jorphan.gui.JFactory; import org.apache.jorphan.gui.JMeterUIDefaults; import org.apache.jorphan.gui.ui.TextComponentUI; +import org.apache.jorphan.util.StringWrap; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.Theme; @@ -294,6 +295,30 @@ protected RUndoManager createUndoManager() { return undoManager; } + // Default limited to 110K + private static final int MAX_LINE_SIZE = + JMeterUtils.getPropDefault("view.results.tree.max_line_size", 110_000); // $NON-NLS-1$ + + // Limit the soft wrap to 100K (hard limit divided by 1.1) + private static final int SOFT_WRAP_LINE_SIZE = + JMeterUtils.getPropDefault("view.results.tree.soft_wrap_line_size", (int) (MAX_LINE_SIZE / 1.1f)); // $NON-NLS-1$ + + private static String wrapLongLines(String input) { + if (input == null || input.isEmpty()) { + return input; + } + if (SOFT_WRAP_LINE_SIZE > 0 && MAX_LINE_SIZE > 0) { + StringWrap stringWrap = new StringWrap(SOFT_WRAP_LINE_SIZE, MAX_LINE_SIZE); + return stringWrap.wrap(input, "\n"); + } + return input; + } + + @Override + public void setText(String t) { + super.setText(wrapLongLines(t)); + } + /** * Sets initial text resetting undo history *