Skip to content

[SR-11355] String.range(of...) matches an extra NUL (and returns range outside string boundaries) #53756

@swift-ci

Description

@swift-ci
Previous ID SR-11355
Radar None
Original Reporter yonilevy (JIRA User)
Type Bug
Environment
  • Swift 5

  • Xcode 10.3

  • MacOS 10.14.6

Additional Detail from JIRA
Votes 1
Component/s Standard Library
Labels Bug
Assignee None
Priority Medium

md5: 5026fff9c23d99a0d147ad5d53b56b68

Issue 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.standard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions