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-4218] [String] Non-empty strings compare equal to empty strings #374

Closed
tbkka opened this issue Mar 10, 2017 · 7 comments
Closed

[SR-4218] [String] Non-empty strings compare equal to empty strings #374

tbkka opened this issue Mar 10, 2017 · 7 comments

Comments

@tbkka
Copy link

tbkka commented Mar 10, 2017

Previous ID SR-4218
Radar None
Original Reporter @tbkka
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library, XCTest
Labels Bug, Linux
Assignee None
Priority Medium

md5: e2cfdb4ceda2c28163bf20fcffb6441d

Issue Description:

The following test succeeds on macOS, fails on Linux:

   XCTAssertNotEqual("", "\u{01}")

I believe it should succeed on all platforms.

I've seen this with the 3.0.2 release version on Ubuntu 16.04, the 3.1 snapshot from March 8 on Ubuntu 16.10, and the trunk snapshot from March 9 on Ubuntu 16.10.

@tbkka
Copy link
Author

tbkka commented Mar 30, 2017

This is still broken on Swift 3.1 Release on Ubuntu 16.10

@tbkka
Copy link
Author

tbkka commented Jun 7, 2017

This is still broken in the Swift 4.0 DEV snapshot for Ubuntu 14.04 released on May 29, 2017.

@alblue
Copy link
Contributor

alblue commented Jul 4, 2017

This doesn't appear to be related to the XCTest libraries; it's pure Swift stdlib:

http://swift.sandbox.bluemix.net/#/repl/595bac27bc7c2268561f6f27

{{let empty = ""
let nonEmpty = "\u{01}"
let result = empty == nonEmpty
print(result)
}}

@alblue
Copy link
Contributor

alblue commented Jul 4, 2017

The equality call shells out to this code:

https://github.com/apple/swift/blob/2b92530dfa85a017af046f3576a366e6ff914555/stdlib/public/stubs/UnicodeNormalization.cpp#L181-L215

{{
swift::_swift_stdlib_unicode_compare_utf8_utf8(const unsigned char *LeftString,
int32_t LeftLength,
const unsigned char *RightString,
int32_t RightLength) {
UCharIterator LeftIterator;
UCharIterator RightIterator;
UErrorCode ErrorCode = U_ZERO_ERROR;

uiter_setUTF8(&LeftIterator, reinterpret_cast<const char *>(LeftString), LeftLength);
uiter_setUTF8(&RightIterator, reinterpret_cast<const char *>(RightString), RightLength);

uint32_t Diff = ucol_strcollIter(GetRootCollator(),
&LeftIterator, &RightIterator, &ErrorCode);
if (U_FAILURE(ErrorCode)) {
swift::crash("ucol_strcollIter: Unexpected error doing utf8<->utf8 string comparison.");
}
return Diff;
}
}}

I suspect what's happening is the control characters (<20) are being handled in a different way in the iterator, which is why the result is being discarded. Compare:

print("" == "\u{19}") // true
print("" == "\u{20}") // false

@tbkka
Copy link
Author

tbkka commented Feb 14, 2018

This is still broken in the current Swift 4.1 DEV snapshots.

@Dante-Broggi
Copy link

Has this been fixed? If so this should be closed.

@tbkka
Copy link
Author

tbkka commented Jul 18, 2018

I no longer see this in 4.2. 🙂

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 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

3 participants