From f2bda4817d3bb530871ea13d2a3186f1b08ba048 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Fri, 3 Dec 2021 11:29:59 +0000 Subject: [PATCH] Update getRealPath() test Changes due to https://github.com/eclipse-ee4j/servlet-api/issues/105 --- .../servletcontext/TestServlet.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java b/src/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java index 803018ac13..f7bdb3be31 100644 --- a/src/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java +++ b/src/com/sun/ts/tests/servlet/api/jakarta_servlet/servletcontext/TestServlet.java @@ -150,7 +150,7 @@ public void getMimeType_1(ServletRequest request, ServletResponse response) */ public void getRealPath(ServletRequest request, ServletResponse response) throws ServletException, IOException { - boolean passed = false; + boolean passed = true; PrintWriter pw = response.getWriter(); String path = "/servlet_js_ServletContext/Test"; @@ -166,13 +166,26 @@ public void getRealPath(ServletRequest request, ServletResponse response) if ((realPath == null) || (realPath.indexOf(path) > -1) || // UNIX path (realPath.indexOf(win32Path) > -1)) // Win32 path { - passed = true; pw.println("realPath = " + realPath); } else { passed = false; pw.println("getRealPath(" + path + ") did not contain the named files"); pw.println("Actual result = " + realPath + " "); } + + // Leading '/' is optional. Ensure the result is the same with or without it + String pathNoSolidus = path.substring(1); + String realPathNoSolidus = context.getRealPath(pathNoSolidus); + + if (realPath == null && realPathNoSolidus == null || + realPath != null && realPath.equals(realPathNoSolidus)) { + pw.println("realPathNoSolidus = " + realPathNoSolidus); + } else { + passed = false; + pw.println("getRealPath(" + path + ") returned [" + realPath + "]"); + pw.println("getRealPath(" + pathNoSolidus + ") returned [" + realPathNoSolidus + "]"); + pw.println("The return values should be the same"); + } ServletTestUtil.printResult(pw, passed); }