Skip to content

Commit

Permalink
Merge pull request #4335 from eclipse/jetty-9.4.x-improve-error-handl…
Browse files Browse the repository at this point in the history
…er-output

Issue #4334 - Improve testing of ErrorHandler behavior
  • Loading branch information
joakime committed Nov 20, 2019
2 parents cba60d2 + cf0df6e commit ba1fe28
Show file tree
Hide file tree
Showing 2 changed files with 288 additions and 77 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -481,24 +482,24 @@ private void writeErrorJson(HttpServletRequest request, PrintWriter writer, int
writer.append(json.entrySet().stream()
.map(e -> QuotedStringTokenizer.quote(e.getKey()) +
":" +
QuotedStringTokenizer.quote((e.getValue())))
QuotedStringTokenizer.quote(StringUtil.sanitizeXmlString((e.getValue()))))
.collect(Collectors.joining(",\n", "{\n", "\n}")));


}

protected void writeErrorPageStacks(HttpServletRequest request, Writer writer)
throws IOException
{
Throwable th = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (_showStacks && th != null)
if (th != null)
{
PrintWriter pw = writer instanceof PrintWriter ? (PrintWriter)writer : new PrintWriter(writer);
pw.write("<pre>");
while (th != null)
writer.write("<h3>Caused by:</h3><pre>");
// You have to pre-generate and then use #write(writer, String)
try (StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw))
{
th.printStackTrace(pw);
th = th.getCause();
pw.flush();
write(writer, sw.getBuffer().toString()); // sanitize
}
writer.write("</pre>\n");
}
Expand Down

0 comments on commit ba1fe28

Please sign in to comment.