Refactor: Add explicit StringComparison to string comparison methods#13
Open
JoonghyunCho wants to merge 1 commit intomainfrom
Open
Refactor: Add explicit StringComparison to string comparison methods#13JoonghyunCho wants to merge 1 commit intomainfrom
JoonghyunCho wants to merge 1 commit intomainfrom
Conversation
Replace culture-sensitive string operations with explicit StringComparison.Ordinal to ensure locale-independent behavior across all Tizen device locales. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds explicit
StringComparison.Ordinalarguments to string comparison methods that were previously using the default culture-sensitive behavior. The changes span 14 files acrossTizen.NUIandTizen.Pims.Calendar.Background
Several .NET string methods use
CurrentCulturewhen noStringComparisonis specified:String.Compare(a, b)CurrentCulture.StartsWith(string)CurrentCulture.EndsWith(string)CurrentCulture.IndexOf(string)CurrentCulture.Equals(string)Ordinal✅.Contains(string)Ordinal(.NET 5+) ✅Since TizenFX runs on global devices (including Turkish, Arabic, German locales), relying on
CurrentCulturefor internal symbol/protocol/format string comparisons can cause subtle, hard-to-reproduce bugs — most famously the "Turkish I problem" where case-insensitive culture comparisons yield unexpected results.This is also flagged by FxCop rules CA1307 and CA1309.
Changes
Tizen.Pims.Calendar— 5 changesCalendarDatabase.csString.Compare(CalendarViews.*.Uri, record.Uri) == 0→.Equals(record.Uri, StringComparison.Ordinal)"tizen.calendar/book"are internal ASCII constants;String.ComparewithoutStringComparisondefaults toCurrentCulture.Tizen.NUI— 35 changesBaseComponents/ImageView.cs(6 changes)StartsWith("*Resource*")→StartsWith("*Resource*", StringComparison.Ordinal)— resource URL markerStartsWith("dali://")/StartsWith("enbuf://")→ Ordinal — internal DALi protocol prefixesViewProperty/ImageShadow.cs(1 change)StartsWith("*Resource*")→ OrdinalBaseComponents/ViewBindableProperty.cs(1 change)StartsWith("*Resource*")→ OrdinalVisuals/VisualObject/ImageVisual.cs(2 changes)StartsWith("dali://")/StartsWith("enbuf://")→ OrdinalCommon/Color.cs(2 changes)StartsWith("RGBA(")/StartsWith("RGB(")→ Ordinal — color format string parsinginternal/XamlBinding/TizenPlatformServices.cs(1 change)StartsWith("System.")/StartsWith("Microsoft.")/StartsWith("mscorlib")→ Ordinal — assembly name filteringpublic/Utility/SpTypeConverter.cs(1 change)public/Utility/DpTypeConverter.cs(2 changes)public/Utility/SdpTypeConverter.cs(1 change)public/Utility/PointTypeConverter.cs(6 changes)public/Utility/GraphicsTypeManager.cs(6 changes)EndsWith("sp"),EndsWith("dp"),EndsWith("px"),EndsWith("sdp"),EndsWith("pt"),EndsWith("spx")→ Ordinalpublic/BaseComponents/TextLabel.cs(4 changes)Equals("BEGIN")/Equals("CENTER")/Equals("TOP")→ Ordinalstring.Equals(string)is already Ordinal in .NET 5+; these changes are for explicitness and consistency.internal/XamlBinding/BindingExpression.cs(2 changes)EndsWith("IElementController.SetValueFromRenderer")→ Ordinal — method name matchingEndsWith(".")→ Ordinal — decimal input validationRisk Assessment
All 41 changes carry no practical risk:
CurrentCultureandOrdinalproduce identical results for pure ASCII strings in all locales.Equals()changes inTextLabel.csare behaviorally a no-op (instanceEqualswas already Ordinal in .NET 5+).internal/privateimplementation code.Scope
StringComparisonis part ofSystemnamespace