• Icon: Bug Bug
    • Resolution: Not A Defect
    • Icon: Minor Minor
    • groovy-plugin, pipeline
    • None
    • Jenkins 2.164.1
      Pipeline:groovy 2.70

       

      Hello! When i use .slit() method with '.' as delimiter, it's work incorrectly. If i use any other char, like ',' - it's work as expected, but not with '.'

       

      Problem code:

      script {
          RC_FILES = '4,5,6'
          println RC_FILES.getClass()
      
          VERSION_TAIL_0 = '1.2.3'
          println VERSION_TAIL_0.getClass()
      
          ARRAY01 = RC_FILES.split(",")
          ARRAY02 = VERSION_TAIL_0.split('.')
      
          ARRAY01.each {
              println("$it")
          }
      
          ARRAY02.each {
              println("$it")
          }
      }
      

      Expected output:

       

       

      [Pipeline] echo
      class java.lang.String 
      [Pipeline] echo 
      class java.lang.String
      [Pipeline] echo
      4
      [Pipeline] echo
      5
      [Pipeline] echo
      6
      [Pipeline] echo
      1
      [Pipeline] echo
      2
      [Pipeline] echo
      3
      
      

      Current output:

       

       

      [Pipeline] echo
      class java.lang.String
      [Pipeline] echo
      class java.lang.String
      [Pipeline] echo
      4
      [Pipeline] echo
      5
      [Pipeline] echo
      6
      

       

          [JENKINS-58552] .split('.') method works incorrect

          gek added a comment -

          Oh, workaround was to use double backslashes:

          script {
              RC_FILES = '4,5,6'
              println RC_FILES.getClass()
          
              VERSION_TAIL_0 = '1.2.3'
              println VERSION_TAIL_0.getClass()
          
              ARRAY01 = RC_FILES.split(",")
              ARRAY02 = VERSION_TAIL_0.split('\\.')
          
              ARRAY01.each {
                  println("$it")
              }
          
              ARRAY02.each {
                  println("$it")
              }
          }
          

          it was two wasted hours of my life...

          gek added a comment - Oh, workaround was to use double backslashes: script { RC_FILES = '4,5,6' println RC_FILES.getClass() VERSION_TAIL_0 = '1.2.3' println VERSION_TAIL_0.getClass() ARRAY01 = RC_FILES.split( "," ) ARRAY02 = VERSION_TAIL_0.split( '\\.' ) ARRAY01.each { println( "$it" ) } ARRAY02.each { println( "$it" ) } } it was two wasted hours of my life...

          Mark Waite added a comment -

          This is a user misunderstanding. The split method takes a regular expression argument. When "." is used as a regular expression, it matches any character. To match a literal ".", use either "[.]" or the backslash escaped "." character

          Mark Waite added a comment - This is a user misunderstanding. The split method takes a regular expression argument. When "." is used as a regular expression, it matches any character. To match a literal ".", use either " [.] " or the backslash escaped "." character

            vjuranek vjuranek
            gek gek
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: