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

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

GitHub user zsomborklara opened a pull request:

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

    LOG4J2-1216: Nested pattern layout options broken

    Change is for the most part as suggested by the original reported of the 
issue in the Jira, I only added a unit test. I made one small modification:
    ```
    if (depth > 0) {          // option not closed, continue with pattern on 
opening "{"
        return begin-1;
    }
    ```
    Turned to:
    ```
    if (depth > 0) {          // option not closed, continue with pattern after 
closing bracket
       return pattern.indexOf('}', start) + 1;
    }
    ```
    Because the original version was breaking 
PatternParserTest#testCustomPattern.
    
    Also it seems there are 3 unit test in core that are broken on head.

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

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

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

    https://github.com/apache/logging-log4j2/pull/111.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 #111
    
----
commit 36919e2c72cfb88af5aca1ea4fd629b4bf5bac6d
Author: zsomborklara <[email protected]>
Date:   2017-09-28T15:28:03Z

    LOG4J2-1216: Nested pattern layout options broken

----


> 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
>            Reporter: Thies Wellpott
>              Labels: easyfix
>
> 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)

Reply via email to