logging-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-1216) Nested pattern layout options broken
Date Thu, 12 Oct 2017 11:21:00 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-1216?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16201802#comment-16201802
] 

ASF GitHub Bot commented on LOG4J2-1216:
----------------------------------------

GitHub user GFriedrich opened a pull request:

    https://github.com/apache/logging-log4j2/pull/116

    [LOG4J2-1216] fix PatternParser for patterns without closing brackets

    This fixes an endless parsing for broken patterns without closing brackets like "%d{"
or patterns where closing brackets only exist for parts of the pattern before a "{" like "}%d{".

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/GFriedrich/logging-log4j2 master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/logging-log4j2/pull/116.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #116
    
----
commit 92ef7be3cb7133f00bcd39413e08444897208992
Author: Georg Friedrich <magicball@gmx.de>
Date:   2017-10-12T11:13:55Z

    [LOG4J2-1216] fix PatternParser for patterns without closing brackets

----


> Nested pattern layout options broken
> ------------------------------------
>
>                 Key: LOG4J2-1216
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1216
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Pattern Converters
>    Affects Versions: 2.4.1, 2.9.1
>            Reporter: Thies Wellpott
>              Labels: easyfix
>             Fix For: 2.9.2
>
>
> Parsing the "deeply" nested PatternLayout
> {code}
> %maxLen{[XXX, ${hostName}, ${web:contextPath}] %p: %c{1} - %m%notEmpty{ =>%ex{short}}}{160}
> {code}
> (with %maxLen being a custom Converter)
> results in wrong parsing.
> Patternparser.extractOptions() gets the nesting wrong.
> Solution:
> {code}
> private static int extractOptions(final String pattern, final int start, final List<String>
options) {
>     int i = start;
>     while (i < pattern.length()  &&  pattern.charAt(i) == '{') {
>         i++;                      // skip opening "{"
>         final int begin = i;      // position of first real char
>         int depth = 1;            // already inside one level
>         while (depth > 0  &&  i < pattern.length()) {
>             char c = pattern.charAt(i);
>             if (c == '{') {
>                 depth++;
>             } else if (c == '}') {
>                 depth--;
>             // TODO(?) maybe escaping of { and } with \ or %
>             }
>             i++;
>         } // while
>         if (depth > 0) {          // option not closed, continue with pattern on opening
"{"
>             return begin-1;
>         }
>         options.add(pattern.substring(begin, i-1));
>     } // while
>     return i;
> }
> {code}
> This should also be faster than the current implementation because the pattern ist only
walked once, not multiple times with indexOf().
> (LOG4J2-107 is a similar but old bug)



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Mime
View raw message