Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-1204] Truncated result of stringByAddingPercentEncodingWithAllowedCharacters #4360

Closed
swift-ci opened this issue Apr 10, 2016 · 6 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-1204
Radar None
Original Reporter kipelovets (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

ubuntu15.10

Additional Detail from JIRA
Votes 1
Component/s Foundation
Labels Bug, Linux
Assignee mbvreddy (JIRA)
Priority Medium

md5: ed86625d88e9266d98e1564e22c6c719

duplicates:

  • SR-3052 [Foundation] Incorrect result of string methods while working with non latin symbols

Issue Description:

Hello

I've noticed that `stringByAddingPercentEncodingWithAllowedCharacters` returns truncated result if the original string contains non-latin UTF characters. The result is encoded properly, but the last few symbols are missing, seems like a problem of calculating the length of resulting string

I'm having problems with Polish and Russian strings like: ''Łódź", "Москва" (I've added some digits on the ends of strings just for padding to see them disappearing in the resulting strings)

This reproduces on ubuntu15.10 and latest Swift development snapshot 2016-03-24. I've created a small example project demonstrating the issue here: https://github.com/kipelovets/SwiftUrlEncode

I also checked IBM sandbox and the issue reproduces on all available versions (3.0 Mar 1, 3.0 Feb 25, 2.2 Jan 11, 2.2 Jan 6). See the sandbox here: http://swiftlang.ng.bluemix.net/#/repl/3b7cd84828b080f7007ffbbb70db850e144aa3ab5e703433a7357a34f13609c3

@swift-ci
Copy link
Contributor Author

Comment by Bhaktavatsal Reddy (JIRA)

characters in input string is double byte characters, when encoded occupy 2 bytes. However, current implementation encodes string based on string length instead of encoded byte length of string. So, rest of the characters gets truncated depending upon no.of multibyte characters present in string.

@swift-ci
Copy link
Contributor Author

Comment by Bhaktavatsal Reddy (JIRA)

Fixed the issue. Running few tests and adding new.

@swift-ci
Copy link
Contributor Author

Comment by Bhaktavatsal Reddy (JIRA)

Another issue unearthed while running test. length of string constructed back by CFStringCreateWithBytes() mess up the length of the string.

@swift-ci
Copy link
Contributor Author

Comment by Gabriel Araujo (JIRA)

I'm also having this problem.. Any other input on this?

@swift-ci
Copy link
Contributor Author

Comment by Bhaktavatsal Reddy (JIRA)

Looks like this issue is fixed with #706 Please test with latest snapshot.

@swift-ci
Copy link
Contributor Author

Comment by Bhaktavatsal Reddy (JIRA)

This issue is fixed as part of https://bugs.swift.org/browse/SR-3052

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant