You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bu...@apache.org on 2020/10/04 06:36:15 UTC

[Bug 57341] [PATCH] JUnitReport task causes OutOfMemoryError/StackOverflowError at junit_frames.br$dash$replace()

https://bz.apache.org/bugzilla/show_bug.cgi?id=57341

--- Comment #10 from Cristian <m3...@icloud.com> ---
--- junit-frames.xsl.orig       2014-12-11 13:03:07.080917200 +0000
+++ junit-frames.xsl    2014-12-11 13:01:36.280917200 +0000
@@ -928,19 +928,36 @@
     @param word the text from which to convert CR to BR tag
 -->
 <xsl:template name="br-replace">
-    <xsl:param name="word"/>
-    <xsl:choose>
-      <xsl:when test="contains($word, '&#xa;')">
-        <xsl:value-of select="substring-before($word, '&#xa;')"/>
-        <br/>
-        <xsl:call-template name="br-replace">
-          <xsl:with-param name="word" select="substring-after($word,
'&#xa;')"/>
-        </xsl:call-template>
-      </xsl:when>
-      <xsl:otherwise>
-       <xsl:value-of select="$word"/>
-      </xsl:otherwise>
-    </xsl:choose>
+  <xsl:param name="word"/>
+  <xsl:param name="splitlimit">32</xsl:param>
+  <xsl:variable name="secondhalflen"
select="(string-length($word)+(string-length($word) mod 2)) div 2"/>
+  <xsl:variable name="secondhalfword" select="substring($word,
$secondhalflen)"/>
+  <!-- When word is very big, a recursive replace is very heap/stack
expensive, so subdivide on line break after middle of string -->
+  <xsl:choose>
+    <xsl:when test="(string-length($word) > $splitlimit) and
(contains($secondhalfword, '&#xa;'))">
+      <xsl:variable name="secondhalfend"
select="substring-after($secondhalfword, '&#xa;')"/>
+      <xsl:variable name="firsthalflen" select="string-length($word) -
$secondhalflen"/>
+      <xsl:variable name="firsthalfword" select="substring($word, 1,
$firsthalflen)"/>
+      <xsl:variable name="firsthalfend"
select="substring-before($secondhalfword, '&#xa;')"/>
+      <xsl:call-template name="br-replace">
+        <xsl:with-param name="word"
select="concat($firsthalfword,$firsthalfend)"/>
+      </xsl:call-template>
+      <br/>
+      <xsl:call-template name="br-replace">
+        <xsl:with-param name="word" select="$secondhalfend"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:when test="contains($word, '&#xa;')">
+      <xsl:value-of select="substring-before($word, '&#xa;')"/>
+      <br/>
+      <xsl:call-template name="br-replace">
+        <xsl:with-param name="word" select="substring-after($word, '&#xa;')"/>

-- 
You are receiving this mail because:
You are the assignee for the bug.