Uploaded image for project: 'Swift'
  1. Swift
  2. SR-11936

String.split(separatedBy:) splits incorrectly for "\r" or "\n" if string contains "\r\n"

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Invalid
    • Component/s: None
    • Labels:
      None

      Description

      To demonstrate the issue, this code:

       

      print("split using \\r: ", "test\r\n123\r\nhello\r\n".split(separator: "\r", omittingEmptySubsequences: true)) 

      prints: 

       

      split using \r:  ["test\r\n123\r\nhello\r\n"]
      

      but should print:

       

      split using \r:  ["test", "\n123", "\nhello", "\n"

       

      Similarly,

       

      print("split using \\n: ", "test\r\n123\r\nhello\r\n".split(separator: "\n")
      

       

      prints:

       split using \n:  ["test\r\n123\r\nhello\r\n"]  
      

      but should print:

      split using \n:  ["test\r", "123\r", "hello\r", ""] 
      

       

      Easily reproduced in a playground.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            Krutsinger Charles
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: