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

String.range(of...) matches an extra NUL (and returns range outside string boundaries)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Standard Library
    • Labels:
      None
    • Environment:
      • Swift 5
      • Xcode 10.3
      • MacOS 10.14.6

      Description

      This is pretty self explanatory:

      let str = "bar"
      if str.range(of: "r\u{0}")!.upperBound > str.endIndex {
          print("Weird!")
      }
      

      I'd expect:
      1) the `str.range()` to return `nil`
      2) `str.range()` to never return a range outside `str` boundaries

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            yonilevy Yoni Levy
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: