Uploaded image for project: 'Undertow'
  1. Undertow
  2. UNDERTOW-2110

Allow line breaks in predicates

XMLWordPrintable

      When typing a complex rule in the predicate language, there doesn't appear to be any way to break up a series of predicates across more than one line.  

      This hard-to-read example works:

       

      regex( "^/foo" ) and regex( value="%q", pattern="p1=([0-9]+)" ) and regex( value="%q", pattern="p2=([a-z]+)" ) -> rewrite( "/bar" ) 

      but this more readable version fails 

      regex( "^/foo" )
        and regex( value="%q", pattern="p1=([0-9]+)" )
        and regex( value="%q", pattern="p2=([a-z]+)" )
        -> rewrite( "/bar" ) 

      with the following confusing error message:

      [ERROR] java.util.NoSuchElementException
      [ERROR]         at java.base/java.util.ArrayDeque.removeFirst(Unknown Source)
      [ERROR]         at java.base/java.util.ArrayDeque.pop(Unknown Source)
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.collapseOutput(PredicatedHandlersParser.java:425)
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.handleLineEnd(PredicatedHandlersParser.java:413)
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.parse(PredicatedHandlersParser.java:353)
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.parse(PredicatedHandlersParser.java:326)
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.parse(PredicatedHandlersParser.java:86) 

      It seems reasonable that if the parser just finished parsing a predicate and the next token encountered is "and", "or", "->" then the parser can assume its still on the same rule regardless of any line breaks.  

      Trying to use parenthesis also doesn't work.  This hard-to-read version of the rule with parenthesis around the predicates works:

      ( regex( "^/foo" ) and regex( value="%q", pattern="p1=([0-9]+)" ) and regex( value="%q", pattern="p2=([a-z]+)" ) ) -> rewrite( "/bar" ) 

      But adding the line breaks back in like so:

      ( regex( "^/foo" ) 
        and regex( value="%q", pattern="p1=([0-9]+)" ) 
        and regex( value="%q", pattern="p2=([a-z]+)" ) ) -> rewrite( "/bar" ) 

      gives the following error:

      [ERROR] java.lang.IllegalArgumentException: UT000045: Error parsing predicated handler string Invalid expression:
      ( regex( "^/foo" )
             ^
      [ERROR]         at io.undertow.server.handlers.builder.PredicatedHandlersParser.error(PredicatedHandlersParser.java:736) 

      If there are still open parenthesis in the parsing of predicates, it seems reasonable to have the parser ignore any line breaks until the parentheses block is closed. 

       

       

       

              rhn-cservice-bbaranow Bartosz Baranowski
              bdw429s Brad Wood
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: