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

            Bug ID: 66419
           Summary: Function with varargs argument fails for single
                    argument
           Product: Tomcat 9
           Version: 9.0.65
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: EL
          Assignee: dev@tomcat.apache.org
          Reporter: kara...@gmail.com
  Target Milestone: -----

Function with varargs argument fails for a single argument. The problem was
introduced by fix of bug 60431. The single argument is always coerced into
array which fails for non-array argument. The reason is the test for array type
is done on methods argument which is always array instead of actual argument
type.
The code in question - AstFunction.getValue:

    } else if (inputParameterCount == methodParameterCount &&
            paramTypes[i].isArray()) {
        params[i] = parameters.jjtGetChild(i).getValue(ctx);

Following test should pass but fails on the third expression:
    @Test
    public void testVarargMethod() throws NoSuchMethodException,
SecurityException {
        ExpressionFactory factory = ExpressionFactory.newInstance();
        ELContext context = new StandardELContext(factory);
        context.getFunctionMapper().mapFunction("fn", "format",
String.class.getMethod("format",String.class, Object[].class));

        Object result = factory.createValueExpression(context,
"${fn:format('%s-%s','one','two')}",
                String.class).getValue(context);
        Assert.assertEquals("one-two",result);

        result = factory.createValueExpression(context,
"${fn:format('%s-%s','one,two'.split(','))}",
                String.class).getValue(context);
        Assert.assertEquals("one-two",result);

        result = factory.createValueExpression(context,
"${fn:format('%s','one')}",
                String.class).getValue(context);
        Assert.assertEquals("one",result);
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to