diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7ddec8a0..829e364b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,7 @@ jobs: - name: Set up .NET SDK uses: actions/setup-dotnet@v4 with: - dotnet-version: '5.0.x' + dotnet-version: '6.x' - name: Cache NuGet packages uses: actions/cache@v2 with: diff --git a/.github/workflows/release-automated.yml b/.github/workflows/release-automated.yml index d686f1d9..2c89b036 100644 --- a/.github/workflows/release-automated.yml +++ b/.github/workflows/release-automated.yml @@ -15,13 +15,13 @@ jobs: - name: Set up .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '5.0.x' - - name: Restore .NET dependencies - run: dotnet restore /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/Parse.csproj - - name: Build .NET project - run: dotnet build /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/Parse.csproj -c Release - - name: List output directory contents - run: ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin/Release/netstandard2.0 + dotnet-version: '6.x' + # - name: Restore .NET dependencies + # run: dotnet restore /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/Parse.csproj + # - name: Build .NET project + # run: dotnet build /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/Parse.csproj -c Release + # - name: List output directory contents + # run: ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin/Release/netstandard2.0 - name: Set up Node.js uses: actions/setup-node@v2 with: diff --git a/CHANGELOG.md b/CHANGELOG.md index 918ce5a0..8a1bd385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [3.0.1](https://github.com/parse-community/Parse-SDK-dotNET/compare/3.0.0...3.0.1) (2024-05-24) + + +### Bug Fixes + +* SDK crash on conversion of double type range values to long type ([#342](https://github.com/parse-community/Parse-SDK-dotNET/issues/342)) ([816ba02](https://github.com/parse-community/Parse-SDK-dotNET/commit/816ba02fa3765e01825da741cedb377eb53c97f6)) + # [3.0.0](https://github.com/parse-community/Parse-SDK-dotNET/compare/2.0.0...3.0.0) (2024-05-23) diff --git a/Parse.Tests/JsonTests.cs b/Parse.Tests/JsonTests.cs index ef67f6e8..49688cb1 100644 --- a/Parse.Tests/JsonTests.cs +++ b/Parse.Tests/JsonTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Globalization; using Microsoft.VisualStudio.TestTools.UnitTesting; using Parse.Infrastructure.Utilities; @@ -250,5 +251,29 @@ public void TestSpecialJsonNumbersAndModifiers() Assert.AreEqual(123456789123456789, (JsonUtilities.Parse("{ \"mura\": 123456789123456789 }") as IDictionary)["mura"]); } + + + [TestMethod] + public void TestJsonNumbersAndValueRanges() + { + //Assert.ThrowsException(() => JsonUtilities.Parse("+123456789")); + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"long\": " + long.MaxValue + " }") as IDictionary)["long"], typeof(long)); + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"long\": " + long.MinValue + " }") as IDictionary)["long"], typeof(long)); + + Assert.AreEqual((JsonUtilities.Parse("{ \"long\": " + long.MaxValue + " }") as IDictionary)["long"], long.MaxValue); + Assert.AreEqual((JsonUtilities.Parse("{ \"long\": " + long.MinValue + " }") as IDictionary)["long"], long.MinValue); + + + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + double.MaxValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + double.MinValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); + + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + double.MaxValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], double.MaxValue); + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + double.MinValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], double.MinValue); + + double outOfInt64RangeValue = -9223372036854776000d; + Assert.IsInstanceOfType((JsonUtilities.Parse("{ \"double\": " + outOfInt64RangeValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], typeof(double)); + Assert.AreEqual((JsonUtilities.Parse("{ \"double\": " + outOfInt64RangeValue.ToString(CultureInfo.InvariantCulture) + " }") as IDictionary)["double"], outOfInt64RangeValue); + } + } } diff --git a/Parse/Infrastructure/Utilities/JsonUtilities.cs b/Parse/Infrastructure/Utilities/JsonUtilities.cs index 3f7d5a79..585e2110 100644 --- a/Parse/Infrastructure/Utilities/JsonUtilities.cs +++ b/Parse/Infrastructure/Utilities/JsonUtilities.cs @@ -212,8 +212,20 @@ private bool ParseNumber(out object output) } else { - output = Int64.Parse(m.Value, CultureInfo.InvariantCulture); - return true; + // try to parse to a long assuming it is an integer value (this might fail due to value range differences when storing as double without decimal point or exponent) + if (Int64.TryParse(m.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out long longValue)) + { + output = longValue; + return true; + } + // try to parse as double again (most likely due to value range exceeding long type + else if (Double.TryParse(m.Value, NumberStyles.Any, CultureInfo.InvariantCulture, out double doubleValue)) + { + output = doubleValue; + return true; + } + else + return false; } } diff --git a/Parse/Parse.csproj b/Parse/Parse.csproj index bbd83611..ad42605f 100644 --- a/Parse/Parse.csproj +++ b/Parse/Parse.csproj @@ -3,7 +3,7 @@ netstandard2.0 bin\Release\netstandard2.0\Parse.xml - 3.0.0 + 3.0.1 latest Parse diff --git a/package-lock.json b/package-lock.json index 4ad2bc29..e175a24d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,17 +1,18 @@ { "name": "parse-sdk-dotnet", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "parse-sdk-dotnet", - "version": "3.0.0", + "version": "3.0.1", "devDependencies": { "@droidsolutions-oss/semantic-release-nuget": "1.4.1", "@droidsolutions-oss/semantic-release-update-file": "1.4.0", "@semantic-release/changelog": "6.0.0", "@semantic-release/commit-analyzer": "9.0.2", + "@semantic-release/exec": "6.0.3", "@semantic-release/git": "10.0.1", "@semantic-release/release-notes-generator": "10.0.3", "semantic-release": "19.0.3" @@ -365,6 +366,35 @@ "integrity": "sha512-9Tj/qn+y2j+sjCI3Jd+qseGtHjOAeg7dU2/lVcqIQ9TV3QDaDXDYXcoOHU+7o2Hwh8L8ymL4gfuO7KxDs3q2zg==", "dev": true }, + "node_modules/@semantic-release/exec": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@semantic-release/exec/-/exec-6.0.3.tgz", + "integrity": "sha512-bxAq8vLOw76aV89vxxICecEa8jfaWwYITw6X74zzlO0mc/Bgieqx9kBRz9z96pHectiTAtsCwsQcUyLYWnp3VQ==", + "dev": true, + "dependencies": { + "@semantic-release/error": "^3.0.0", + "aggregate-error": "^3.0.0", + "debug": "^4.0.0", + "execa": "^5.0.0", + "lodash": "^4.17.4", + "parse-json": "^5.0.0" + }, + "engines": { + "node": ">=14.17" + }, + "peerDependencies": { + "semantic-release": ">=18.0.0" + } + }, + "node_modules/@semantic-release/exec/node_modules/@semantic-release/error": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@semantic-release/error/-/error-3.0.0.tgz", + "integrity": "sha512-5hiM4Un+tpl4cKw3lV4UgzJj+SmfNIDCLLw0TepzQxz9ZGV5ixnqkzIVF+3tp0ZHgcMKE+VNGHJjEeyFG2dcSw==", + "dev": true, + "engines": { + "node": ">=14.17" + } + }, "node_modules/@semantic-release/git": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@semantic-release/git/-/git-10.0.1.tgz", diff --git a/package.json b/package.json index 25b44e4d..9eb3598d 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,12 @@ { "name": "parse-sdk-dotnet", - "version": "3.0.0", + "version": "3.0.1", "devDependencies": { "@droidsolutions-oss/semantic-release-nuget": "1.4.1", "@droidsolutions-oss/semantic-release-update-file": "1.4.0", "@semantic-release/changelog": "6.0.0", "@semantic-release/commit-analyzer": "9.0.2", + "@semantic-release/exec": "6.0.3", "@semantic-release/git": "10.0.1", "@semantic-release/release-notes-generator": "10.0.3", "semantic-release": "19.0.3" diff --git a/release.config.js b/release.config.js index b14351ad..247bb4e8 100644 --- a/release.config.js +++ b/release.config.js @@ -78,6 +78,7 @@ async function config() { ['@semantic-release/changelog', { 'changelogFile': changelogFile, }], + // Updates the project version in the semantic release prepare step ['@droidsolutions-oss/semantic-release-update-file', { 'files': [ { @@ -89,6 +90,24 @@ async function config() { } ] }], + // ["@semantic-release/exec", { + // 'verifyConditionsCmd': 'find / -name "Parse.dll" 2>/dev/null', + // 'prepareCmd': 'find / -name "Parse.dll" 2>/dev/null', + // 'publishCmd': 'find / -name "Parse.dll" 2>/dev/null', + // 'successCmd': 'find / -name "Parse.dll" 2>/dev/null', + // 'failCmd': 'find / -name "Parse.dll" 2>/dev/null', + // }], + // ["@semantic-release/exec", { + // 'verifyConditionsCmd': 'ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin 2>/dev/null', + // 'prepareCmd': 'ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin 2>/dev/null', + // 'publishCmd': 'ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin 2>/dev/null', + // 'successCmd': 'ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin 2>/dev/null', + // 'failCmd': 'ls -la /home/runner/work/Parse-SDK-dotNET/Parse-SDK-dotNET/Parse/bin 2>/dev/null', + // }], + // Build the DLL file after the version has been updated + ["@semantic-release/exec", { + 'prepareCmd': 'dotnet build ./Parse/Parse.csproj -c Release', + }], ['@droidsolutions-oss/semantic-release-nuget', { projectPath: './Parse/Parse.csproj', includeSymbols: true,