-
Notifications
You must be signed in to change notification settings - Fork 163
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
Initiating a Locale/Language with empty language code/script/region results in an unreasonable locale. #1102
base: main
Are you sure you want to change the base?
Initiating a Locale/Language with empty language code/script/region results in an unreasonable locale. #1102
Conversation
…esults in an unreasonable locale. Here are some examples: ```swift print(Locale(languageCode: "", script: "", languageRegion: "").identifier) // "-_" let languageComponents = Locale.Language.Components(language: .init(identifier:"")) print(Locale(languageComponents: languageComponents).identifier) // "-Latn" ``` Fix this by handling empty identifiers passed in at initialization time correctly. resolves 132353443
XCTAssertEqual(emptyLocale.language.languageCode, nil) | ||
XCTAssertEqual(emptyLocale.language.script, nil) | ||
XCTAssertEqual(emptyLocale.language.region, nil) | ||
XCTAssertEqual(emptyLocale.language.maximalIdentifier, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently returns "en-Latn-US"
XCTAssertEqual(emptyLocale.language.script, nil) | ||
XCTAssertEqual(emptyLocale.language.region, nil) | ||
XCTAssertEqual(emptyLocale.language.maximalIdentifier, "") | ||
XCTAssertEqual(emptyLocale.language.minimalIdentifier, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently returns "en"
|
||
let emptyLocale = Locale(identifier: "") | ||
XCTAssertEqual(emptyLocale.language.languageCode, nil) | ||
XCTAssertEqual(emptyLocale.language.script, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently returns "Latn"
@swift-ci please test |
@@ -34,11 +34,11 @@ extension Locale { | |||
if let languageCode = languageCode { | |||
result += languageCode._normalizedIdentifier | |||
} | |||
if let script = script { | |||
if let script = script, script != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might prefer !script.isEmpty
Here are some examples:
Fix this by handling empty identifiers passed in at initialization time correctly.
resolves 132353443