From f314c63175f533db91423036ed758ec9c661c478 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Wed, 7 Dec 2022 20:11:32 -0800 Subject: [PATCH] fix: Fixes Point3D TryParse (#1298) --- .../Server.Tests/Tests/Geometry/Point3DTests.cs | 13 +++++++++++++ Projects/Server/Geometry/Point3D.cs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Projects/Server.Tests/Tests/Geometry/Point3DTests.cs b/Projects/Server.Tests/Tests/Geometry/Point3DTests.cs index 9271e89d3..c2ddef41e 100644 --- a/Projects/Server.Tests/Tests/Geometry/Point3DTests.cs +++ b/Projects/Server.Tests/Tests/Geometry/Point3DTests.cs @@ -5,6 +5,15 @@ namespace Server.Tests; public class Point3DTests { + [Theory] + [InlineData("(709, 2236, -2)", 709, 2236, -2)] + public void TestPoint3DRegressions(string text, int x, int y, int z) + { + var successful = Point3D.TryParse(text, null, out var p); + Assert.True(successful); + Assert.Equal(new Point3D(x, y, z), p); + } + [Fact] public void TestPoint3DToString() { @@ -124,5 +133,9 @@ public class Point3DTests Assert.False(Point3D.TryParse("(,23,)", null, out p)); Assert.Equal(default, p); Assert.Throws(() => Point3D.Parse("(,23,)", null)); + + Assert.False(Point3D.TryParse("(23,,-1)", null, out p)); + Assert.Equal(default, p); + Assert.Throws(() => Point3D.Parse("(23,,-1)", null)); } } diff --git a/Projects/Server/Geometry/Point3D.cs b/Projects/Server/Geometry/Point3D.cs index acffdcee3..e1e1b0674 100644 --- a/Projects/Server/Geometry/Point3D.cs +++ b/Projects/Server/Geometry/Point3D.cs @@ -248,7 +248,7 @@ public struct Point3D var offset = firstComma + 1; var secondComma = s[offset..].IndexOfOrdinal(','); - if (secondComma == -1 || offset == secondComma) + if (secondComma == -1) { result = default; return false;