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

String.addingPercentEncoding() mishandles Unicode characters

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Medium
    • Resolution: Cannot Reproduce
    • Component/s: Foundation
    • Labels:

      Description

      `String.addingPercentEncoding(withAllowedCharacters: CharacterSet)` produces incorrect output when the string contains certain Unicode characters. It does not seem to matter which CharacterSet is used.

      This issue occurs on Ubuntu 16.04, but does NOT occur on macOS.
      Tested on Swift 3.0.1 Release and swift-DEVELOPMENT-SNAPSHOT-2016-11-12-a-ubuntu16.04.

      Steps to reproduce:

      ```swift
      import Foundation
      let str = "CaféRio" // Accented "e"
      let escaped = str.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed)!
      print(escaped)
      ```
      Expected output: Caf%C3%A9Rio
      Actual output: Caf%C3%A9Ri

      Notice that the actual Unicode character is escaped correctly, but the resulting string is missing a character at the end. For each "é" inside the string, another trailing character goes missing.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            collinhundley Collin Hundley
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: