|
25 | 25 | import java.util.StringTokenizer;
|
26 | 26 |
|
27 | 27 | import org.junit.Test;
|
28 |
| - |
29 | 28 | import org.springframework.asm.MethodVisitor;
|
30 | 29 | import org.springframework.expression.AccessException;
|
31 | 30 | import org.springframework.expression.EvaluationContext;
|
@@ -522,6 +521,19 @@ public void ternary() throws Exception {
|
522 | 521 | assertEquals(1,expression.getValue(root));
|
523 | 522 | }
|
524 | 523 |
|
| 524 | + @Test |
| 525 | + public void ternaryWithBooleanReturn() { // SPR-12271 |
| 526 | + expression = parser.parseExpression("T(Boolean).TRUE?'abc':'def'"); |
| 527 | + assertEquals("abc",expression.getValue()); |
| 528 | + assertCanCompile(expression); |
| 529 | + assertEquals("abc",expression.getValue()); |
| 530 | + |
| 531 | + expression = parser.parseExpression("T(Boolean).FALSE?'abc':'def'"); |
| 532 | + assertEquals("def",expression.getValue()); |
| 533 | + assertCanCompile(expression); |
| 534 | + assertEquals("def",expression.getValue()); |
| 535 | + } |
| 536 | + |
525 | 537 | @Test
|
526 | 538 | public void elvis() throws Exception {
|
527 | 539 | Expression expression = parser.parseExpression("'a'?:'b'");
|
@@ -1830,7 +1842,6 @@ public void methodReference_simpleInstanceMethodOneArgReturnPrimitive2() throws
|
1830 | 1842 | assertEquals('c',resultC);
|
1831 | 1843 | }
|
1832 | 1844 |
|
1833 |
| - |
1834 | 1845 | @Test
|
1835 | 1846 | public void compoundExpression() throws Exception {
|
1836 | 1847 | Payload payload = new Payload();
|
@@ -1914,7 +1925,18 @@ public void propertyReference() throws Exception {
|
1914 | 1925 | assertCanCompile(expression);
|
1915 | 1926 | assertEquals("value4",expression.getValue(tc));
|
1916 | 1927 | }
|
1917 |
| - |
| 1928 | + |
| 1929 | + @Test |
| 1930 | + public void propertyReferenceVisibility() { // SPR-12771 |
| 1931 | + StandardEvaluationContext ctx = new StandardEvaluationContext(); |
| 1932 | + ctx.setVariable("httpServletRequest", HttpServlet3RequestFactory.getOne()); |
| 1933 | + // Without a fix compilation was inserting a checkcast to a private type |
| 1934 | + expression = parser.parseExpression("#httpServletRequest.servletPath"); |
| 1935 | + assertEquals("wibble",expression.getValue(ctx)); |
| 1936 | + assertCanCompile(expression); |
| 1937 | + assertEquals("wibble",expression.getValue(ctx)); |
| 1938 | + } |
| 1939 | + |
1918 | 1940 | @SuppressWarnings("unchecked")
|
1919 | 1941 | @Test
|
1920 | 1942 | public void indexer() throws Exception {
|
@@ -2954,4 +2976,28 @@ private static class TestClass9 {
|
2954 | 2976 | public TestClass9(int i) {}
|
2955 | 2977 | }
|
2956 | 2978 |
|
| 2979 | + // These test classes simulate a pattern of public/private classes seen in Spring Security |
| 2980 | + |
| 2981 | + // final class HttpServlet3RequestFactory implements HttpServletRequestFactory |
| 2982 | + static class HttpServlet3RequestFactory { |
| 2983 | + |
| 2984 | + static Servlet3SecurityContextHolderAwareRequestWrapper getOne() { |
| 2985 | + HttpServlet3RequestFactory outer = new HttpServlet3RequestFactory(); |
| 2986 | + return outer.new Servlet3SecurityContextHolderAwareRequestWrapper(); |
| 2987 | + } |
| 2988 | + // private class Servlet3SecurityContextHolderAwareRequestWrapper extends SecurityContextHolderAwareRequestWrapper |
| 2989 | + private class Servlet3SecurityContextHolderAwareRequestWrapper extends SecurityContextHolderAwareRequestWrapper { |
| 2990 | + } |
| 2991 | + } |
| 2992 | + |
| 2993 | + // public class SecurityContextHolderAwareRequestWrapper extends HttpServletRequestWrapper |
| 2994 | + static class SecurityContextHolderAwareRequestWrapper extends HttpServletRequestWrapper { |
| 2995 | + } |
| 2996 | + |
| 2997 | + public static class HttpServletRequestWrapper { |
| 2998 | + public String getServletPath() { |
| 2999 | + return "wibble"; |
| 3000 | + } |
| 3001 | + } |
| 3002 | + |
2957 | 3003 | }
|
0 commit comments