You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix wrong bracket matching when parsing Vectors (#3837)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->
<!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->
## Fixes#3834
<!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes#1234) which will automatically close the issue once the PR is merged. -->
<!-- Add a brief overview here of the feature/bug & fix. -->
Fixed wrong bracket matching in `StringExtensions.ToVectorN(string)` and `StringExtensions.ToQuaternion(string)` methods.
## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR. -->
- Bugfix
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->
## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
Sample app crashes.
## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
Sample app does not crash.
## PR Checklist
Please check if your PR fulfills the following requirements:
- [ ] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
- [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets)
- [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/windows-toolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [ ] Contains **NO** breaking changes
<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below.
Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->
## Other information
Copy file name to clipboardExpand all lines: Microsoft.Toolkit.Uwp.UI/Extensions/StringExtensions.cs
+22-24Lines changed: 22 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -29,12 +29,7 @@ public static Vector2 ToVector2(this string text)
29
29
if(text.Length>0)
30
30
{
31
31
// The format <x> or <x, y> is supported
32
-
if(text.Length>=2&&
33
-
text[0]=='>'&&
34
-
text[text.Length-1]=='>')
35
-
{
36
-
text=text.Substring(1,text.Length-2);
37
-
}
32
+
text=Unbracket(text);
38
33
39
34
// Skip allocations when only a component is used
40
35
if(text.IndexOf(',')==-1)
@@ -78,12 +73,7 @@ public static Vector3 ToVector3(this string text)
78
73
{
79
74
if(text.Length>0)
80
75
{
81
-
if(text.Length>=2&&
82
-
text[0]=='>'&&
83
-
text[text.Length-1]=='>')
84
-
{
85
-
text=text.Substring(1,text.Length-2);
86
-
}
76
+
text=Unbracket(text);
87
77
88
78
if(text.IndexOf(',')==-1)
89
79
{
@@ -127,12 +117,7 @@ public static Vector4 ToVector4(this string text)
127
117
{
128
118
if(text.Length>0)
129
119
{
130
-
if(text.Length>=2&&
131
-
text[0]=='>'&&
132
-
text[text.Length-1]=='>')
133
-
{
134
-
text=text.Substring(1,text.Length-2);
135
-
}
120
+
text=Unbracket(text);
136
121
137
122
if(text.IndexOf(',')==-1)
138
123
{
@@ -176,12 +161,7 @@ public static Quaternion ToQuaternion(this string text)
176
161
{
177
162
if(text.Length>0)
178
163
{
179
-
if(text.Length>=2&&
180
-
text[0]=='>'&&
181
-
text[text.Length-1]=='>')
182
-
{
183
-
text=text.Substring(1,text.Length-2);
184
-
}
164
+
text=Unbracket(text);
185
165
186
166
string[]values=text.Split(',');
187
167
@@ -201,5 +181,23 @@ public static Quaternion ToQuaternion(this string text)
201
181
202
182
staticQuaternionThrow(stringtext)=>thrownewFormatException($"Cannot convert \"{text}\" to {nameof(Quaternion)}. Use the format \"float, float, float, float\"");
203
183
}
184
+
185
+
/// <summary>
186
+
/// Converts an angle bracketed <see cref="string"/> value to its unbracketed form (e.g. "<float, float>" to "float, float").
187
+
/// If the value is already unbracketed, this method will return the value unchanged.
0 commit comments