You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Mark Thomas <ma...@apache.org> on 2008/09/18 22:00:25 UTC

EL and TCK

With the recent fixes to the EL code it appears that there is a bug in the
TCK. I won't repeat the exact test since the TCK licence won't let me do
that but a simple version is that the TCK thinks the following expression
should be valid:

${\'string literal\'}

For those of you with access to the TCK, mail me privately if you want the
real expression the TCK is using.

My reading of the EL spec is that string literals *must* be quoted. Single
or double, take you pick but you have to use one or the other. Note that
the quotes in the example above are escaped so they don't count.

Before I embark on trying to convince the EG there is a bug in the TCK can
anyone see a reason why the above?

Cheers,

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Remy Maucherat <re...@apache.org>.
On Mon, 2008-09-22 at 22:54 +0100, Mark Thomas wrote:
> This is currently being raised with the EG for clarification. I'll let
> people know when I receive a response. It should be ~3 weeks max.

Ok, cool :)

Rémy



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Mark Thomas <ma...@apache.org>.
This is currently being raised with the EG for clarification. I'll let
people know when I receive a response. It should be ~3 weeks max.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Mark Thomas <ma...@apache.org>.
Konstantin Kolinko wrote:
> Mark,
> 
> I tend to agree with your reading of the EBNF grammar there, but I think that
> the grammar is wrong.
Unfortunately, we have to implement the spec. If we think it is wrong we
can ask the EG for a clarification but in the mean time we should be compliant.

> The first sentence of "Quoting in Attributes" part in JSP.1.6 says:
> "Quotation is done consistently regardless of whether the attribute value is a
> literal or a request-time attribute expression."
> 
> <x:tag value="${"Joe said 'hello'"}"/>
> is not a consistent quoting, IMHO.
Indeed, but the spec also states that the grammar has precedence over the text.

> Also, from historical perspective, do you think that quoting rules has changed
> between JSP 1.2 and 2.0?
I don't know. My brain hurts enough from just the 2.1 spec - I don't think
I can face reading another one ;)

> So, the error in EBNF is also present in JSP 2.0.
<sarcasm>Great</sarcasm>

> Implementation of JSP 2.0 can be tested with Tomcat 5.5, and the following:
> 
> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
> <c:out value="${ \"Joe said 'hello'\" }" />
> 
> prints the string in TC 5.5.25, and the expression without the slashes produces
> error 500 ("equal symbol expected") at compile time.
6.0.x usually fails in the same way but it isn't always consistent. Before
it is fixed, we need to figure out what the correct behaviour is.

> I do not have "strict
> compliance" configured, if that matters.
I don't believe it does in this case.

> I also thought, how the error in the EBNF grammar could be corrected, but
> the most simple way IMHO would be to explain the issue in a comment, or
> replace the reference to EL grammar (inclusion of it) with a vc: validity
> constraint (JSP.1.3.10.2),
> rather than to try to express it all as pure EBNF productions.
I'm not sure it should be fixed. See
https://issues.apache.org/bugzilla/show_bug.cgi?id=45451
If quoting was applied consistently things would have to be double escaped.
You'd have tag attributes of the form
attr="${\"\\\\\\\"\"}"
which equates to the EL
${"\\\""}
which evaluates to
\"

With the current grammar you'd have tag attributes of the form
attr="${"\\\""}"
which equates to the EL
${"\\\""}
which evaluates to
\"

I find the latter easier to read although the trick is how you parse it. I
need to have a think about edge cases, particularly with quoted }, to see
if the current grammar can be parsed unambiguously.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Konstantin Kolinko <kn...@gmail.com>.
2008/9/19 Mark Thomas <ma...@apache.org>:
> Mark Thomas wrote:
>> Konstantin Kolinko wrote:
>>> In JSP 2.1 spec there is chapter
>>> JSP.1.6 Quoting and Escape Conventions
>>> - see "Quoting in Attributes" part there.
>>>
>>> Thus, IMHO, ${\'string literal\'} will be valid if used as the value for
>>> an attribute of custom tag.
> I've looked at this again and I don't believe this is valid, even if used
> as the value for a tag attribute.
>
>>> The example from the spec
>>> <x:tag value="<%= \"Joe said 'hello'\" %>"/>
>>> becomes
>>> <x:tag value="${ \"Joe said 'hello'\" }"/>
> I think this should be:
> <x:tag value="${"Joe said 'hello'"}"/>
>
> My reasoning is as follows (quoting selectively from JSP.1.3.10)
>
> This section presents a simple EBNF grammar for the JSP syntax. The grammar
> is intended to provide a concise syntax overview and to resolve any syntax
> ambiguities present in this specification. Other sections may apply further
> restrictions to this syntax, for example to restrict what represents a
> valid attribute value for a page directive. In all other cases the grammar
> takes precedence in resolving syntax questions.
>
> So, starting with Attribute:
>
> Attribute ::= Name Eq
> (skipped...)
>

Mark,

I tend to agree with your reading of the EBNF grammar there, but I think that
the grammar is wrong.

The first sentence of "Quoting in Attributes" part in JSP.1.6 says:
"Quotation is done consistently regardless of whether the attribute value is a
literal or a request-time attribute expression."

<x:tag value="${"Joe said 'hello'"}"/>
is not a consistent quoting, IMHO.

Also, from historical perspective, do you think that quoting rules has changed
between JSP 1.2 and 2.0?

JSP 1.2:
IIRC (though only from theory/sources, too little practical experience with
JSP 1.2), in JSTL 1.0 those expressions are just plain strings, passed to
the tags "as is" for evaluation. So, how those were quoted in tag attributes?


JSP 2.0:
Reading the JSP 2.0 specification, the wording in JSP.1.6 and EBNF
expressions in JSP.1.3.10 are exactly the same is in JSP 2.1 spec,
with the exception that the EL language is defined in the same document.

So, the error in EBNF is also present in JSP 2.0.

Implementation of JSP 2.0 can be tested with Tomcat 5.5, and the following:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:out value="${ \"Joe said 'hello'\" }" />

prints the string in TC 5.5.25, and the expression without the slashes produces
error 500 ("equal symbol expected") at compile time. I do not have "strict
compliance" configured, if that matters.

I also thought, how the error in the EBNF grammar could be corrected, but
the most simple way IMHO would be to explain the issue in a comment, or
replace the reference to EL grammar (inclusion of it) with a vc: validity
constraint (JSP.1.3.10.2),
rather than to try to express it all as pure EBNF productions.

There are a lot of comments before the grammar.


Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Mark Thomas <ma...@apache.org>.
Mark Thomas wrote:
> Konstantin Kolinko wrote:
>> In JSP 2.1 spec there is chapter
>> JSP.1.6 Quoting and Escape Conventions
>> - see "Quoting in Attributes" part there.
>>
>> Thus, IMHO, ${\'string literal\'} will be valid if used as the value for
>> an attribute of custom tag.
I've looked at this again and I don't believe this is valid, even if used
as the value for a tag attribute.

>> The example from the spec
>> <x:tag value="<%= \"Joe said 'hello'\" %>"/>
>> becomes
>> <x:tag value="${ \"Joe said 'hello'\" }"/>
I think this should be:
<x:tag value="${"Joe said 'hello'"}"/>

My reasoning is as follows (quoting selectively from JSP.1.3.10)

This section presents a simple EBNF grammar for the JSP syntax. The grammar
is intended to provide a concise syntax overview and to resolve any syntax
ambiguities present in this specification. Other sections may apply further
restrictions to this syntax, for example to restrict what represents a
valid attribute value for a page directive. In all other cases the grammar
takes precedence in resolving syntax questions.

So, starting with Attribute:

Attribute ::= Name Eq
              ( ( ‘”<%=’ RTAttributeValueDouble )
                | ( “‘<%=”RTAttributeValueSingle )
                | ( ‘”’ AttributeValueDouble )
                | ( “‘” AttributeValueSingle )
              )

Then looking at attribute values that use double quotes:

AttributeValueDouble::= ( QuotedChar - ‘”’ )*
                        ( ‘”’ | <TRANSLATION_ERROR> )

QuotedChar I think is key to this. Note the use of \" and \' outside of
${...} but once inside ${...} the rules for ELExpression are followed.

QuotedChar ::= ’&apos;’
             | ’&quot;’
             | ’\\’
             | ‘\”’
             | "\’"
             | ‘\$’
             | ‘\#’
             | ( ‘${‘ ELExpressionBody )
             | ( ‘#{‘ ELExpressionBody )
             | Char
             [ vc: QuotedDollarMatched ]

ELExpressionBody ::= ELExpression ‘}’
                   | <TRANSLATION_ERROR>

ELExpression ::= [See EL spec document, production Expression]


If we follow ELExpression through to StringLiteral in section 1.19 of the
EL spec, no additional quoting is defined.

Expression ::= Expression1 ExpressionRest?

Expression1 ::= Expression BinaryOp Expression
              | UnaryExpression

UnaryExpression ::= UnaryOp UnaryExpression
                  | Value

Value ::= ValuePrefix (ValueSuffix)*

ValuePrefix ::= Literal
              | NonLiteralValuePrefix

Literal ::= BooleanLiteral
          | IntegerLiteral
          | FloatingPointLiteral
          | StringLiteral
          | NullLiteral

StringLiteral ::= '([^'\]|\'|\\)*'
                | "([^”\]|\”|\\)*"
                i.e., a string of any characters enclosed by
                single or double quotes, where \ is used to
                escape ', ",and \. It is possible to use single
                quotes within double quotes, and vice versa,
                without escaping.

I'm quite prepared to believe my logic above is wrong and that am I
misreading the specs in some way. What do others think? Am I right or am I
mis-reading the specs and if I am, where am I going wrong?

Cheers,

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Remy Maucherat <re...@apache.org>.
On Fri, 2008-09-19 at 12:45 +0100, Mark Thomas wrote:
> Tags are involved so it looks like this is a bug in Tomcat rather than the
> TCK. Maybe a regression from my fix for 45427? It might just be me but
> anything in Jasper to do with EL seems really fragile.

I am not aware of this failure, so it would likely be caused by this new
change.

Rémy



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Mark Thomas <ma...@apache.org>.
Konstantin Kolinko wrote:
> In JSP 2.1 spec there is chapter
> JSP.1.6 Quoting and Escape Conventions
> - see "Quoting in Attributes" part there.
> 
> Thus, IMHO, ${\'string literal\'} will be valid if used as the value for
> an attribute of custom tag.
> 
> The example from the spec
> <x:tag value="<%= \"Joe said 'hello'\" %>"/>
> becomes
> <x:tag value="${ \"Joe said 'hello'\" }"/>
> 
> and should have produced the following EL expression:
> "Joe said 'hello'"
> (without any backslash characters in EL text)
> 
> I hope that this explanation matches your case.

Thanks for the reply. The fresh pair of eyes is appreciated.

Tags are involved so it looks like this is a bug in Tomcat rather than the
TCK. Maybe a regression from my fix for 45427? It might just be me but
anything in Jasper to do with EL seems really fragile.

Mark



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: EL and TCK

Posted by Konstantin Kolinko <kn...@gmail.com>.
2008/9/19 Mark Thomas <ma...@apache.org>:
> With the recent fixes to the EL code it appears that there is a bug in the
> TCK. I won't repeat the exact test since the TCK licence won't let me do
> that but a simple version is that the TCK thinks the following expression
> should be valid:
>
> ${\'string literal\'}
>
> For those of you with access to the TCK, mail me privately if you want the
> real expression the TCK is using.
>
> My reading of the EL spec is that string literals *must* be quoted. Single
> or double, take you pick but you have to use one or the other. Note that
> the quotes in the example above are escaped so they don't count.
>
> Before I embark on trying to convince the EG there is a bug in the TCK can
> anyone see a reason why the above?
>

Hi, Mark!

Is the above EL expression a part of some JSP page?

I do not have access to TCK, so I do not know how those tests are
implemented.

In JSP 2.1 spec there is chapter
JSP.1.6 Quoting and Escape Conventions
- see "Quoting in Attributes" part there.

Thus, IMHO, ${\'string literal\'} will be valid if used as the value for
an attribute of custom tag.

The example from the spec
<x:tag value="<%= \"Joe said 'hello'\" %>"/>
becomes
<x:tag value="${ \"Joe said 'hello'\" }"/>

and should have produced the following EL expression:
"Joe said 'hello'"
(without any backslash characters in EL text)

I hope that this explanation matches your case.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org