Issue Type: Bug Bug
Affects Versions: 1.1.2
Assignee: Logback dev list
Components: logback-core
Created: 22/Apr/14 7:49 AM
Description:

When logback attempts to substitute values in for variables (of of the style $

{...}

) in the body of an element in logback.xml, if the body String ends with a dollar sign, '$', line 63 of ch.qos.logback.core.subst.Tokenizer performs:

throw new ScanException("Unexpected end of pattern string");

Which incorrectly throws a ScanException, because it is incorrectly expecting more characters, either a '{' to tell it to expect a variable name, or not a '{', to indicate that the '$' was a literal. If a '$' is the last character, obviously it is a literal instead of the beginning of a variable reference token.

Also, if the body String ends with "${", an NPE is thrown by some other method. Instead, my solution below throws a ScanException in this case (plus for the case where a "$

{" is not closed by a "}

").

Lastly, if the String includes unbalanced '

{' without corresponding closing '}

', your code throws exceptions elsewhere. Why must '

{' be balanced by closing '}

', if the '{' is not preceded by a '$'? My solution doesn't fix this issue, only the previous issues. Assuming my solution works for the earlier issues, however, it should be put into place, and the latter '{' issue can be handled later.

Solution (not tested or even compiled, so it might contain typos):
The body of the switch statement that include line 63 should probably be replaced with something like the following:

case LITERAL_STATE:
final int tokenCount = tokenList.size();
if (tokenCount >= 2 && tokenList.get(tokenCount - 2) == Token.START_TOKEN) {
throw new ScanException("variable reference open, \"$

{\", without a variable reference close, \"}

\" for variable name " + buf);
}
addLiteralToken(tokenList, buf);
break;
case START_STATE:
buf.append(CoreConstants.DOLLAR);
addLiteralToken(tokenList, buf);
break;

Environment:

All

Project: logback
Priority: Major Major
Reporter: Ross Goldberg
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
_______________________________________________
logback-dev mailing list
logback-dev@qos.ch
http://mailman.qos.ch/mailman/listinfo/logback-dev

Reply via email to