From 13aa07f63edda9b0f478b92e64406f75bb398cb2 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Sat, 1 Jun 2013 14:18:20 +1200 Subject: [PATCH] -Fixed potential inifinite loop when parsing unquoted value -Added NuGet install.ps1 -Incremented version to 5.0.6 --- Build/Newtonsoft.Json.nuspec | 2 +- Build/build.ps1 | 14 +-- Build/install.ps1 | 90 +++++++++++++++++++ .../JsonTextReaderTest.cs | 26 ++++++ .../Linq/LinqToJsonTest.cs | 11 +++ .../Properties/AssemblyInfo.cs | 2 +- Src/Newtonsoft.Json/JsonTextReader.cs | 4 + .../Newtonsoft.Json.Net35.csproj | 2 +- .../Properties/AssemblyInfo.cs | 2 +- 9 files changed, 144 insertions(+), 9 deletions(-) create mode 100644 Build/install.ps1 diff --git a/Build/Newtonsoft.Json.nuspec b/Build/Newtonsoft.Json.nuspec index b401cea2..b516ac0c 100644 --- a/Build/Newtonsoft.Json.nuspec +++ b/Build/Newtonsoft.Json.nuspec @@ -2,7 +2,7 @@ Newtonsoft.Json - 5.0.5 + 5.0.6 Json.NET Json.NET is a popular high-performance JSON framework for .NET James Newton-King diff --git a/Build/build.ps1 b/Build/build.ps1 index 5909bb14..32c71c50 100644 --- a/Build/build.ps1 +++ b/Build/build.ps1 @@ -1,12 +1,12 @@ properties { - $zipFileName = "Json50r5.zip" + $zipFileName = "Json50r6.zip" $majorVersion = "4.5" - $majorWithReleaseVersion = "5.0.5" + $majorWithReleaseVersion = "5.0.6" $version = GetVersion $majorWithReleaseVersion $signAssemblies = $false $signKeyPath = "D:\Development\Releases\newtonsoft.snk" $buildDocumentation = $false - $buildNuGet = $false + $buildNuGet = $true $treatWarningsAsErrors = $false $baseDir = resolve-path .. @@ -17,7 +17,7 @@ $releaseDir = "$baseDir\Release" $workingDir = "$baseDir\Working" $builds = @( - @{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net45"; NuGetDir = "net45"; Framework="net-4.0"; Sign=$true}, + @{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net45"; NuGetDir = "net45"; Framework="net-4.0"; Sign=$true} @{Name = "Newtonsoft.Json.Portable"; TestsName = "Newtonsoft.Json.Tests.Portable"; Constants="PORTABLE"; FinalDir="Portable"; NuGetDir = "portable-net45+wp80+win8"; Framework="net-4.0"; Sign=$true}, @{Name = "Newtonsoft.Json.Portable40"; TestsName = "Newtonsoft.Json.Tests.Portable40"; Constants="PORTABLE40"; FinalDir="Portable40"; NuGetDir = "portable-net40+sl4+wp7+win8"; Framework="net-4.0"; Sign=$true}, @{Name = "Newtonsoft.Json.WinRT"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="WinRT"; NuGetDir = "netcore45"; Framework="net-4.5"; Sign=$true}, @@ -77,11 +77,15 @@ task Package -depends Build { if ($buildNuGet) { New-Item -Path $workingDir\NuGet -ItemType Directory + New-Item -Path $workingDir\NuGet\tools -ItemType Directory + Copy-Item -Path "$buildDir\Newtonsoft.Json.nuspec" -Destination $workingDir\NuGet\Newtonsoft.Json.nuspec -recurse + Copy-Item -Path "$buildDir\install.ps1" -Destination $workingDir\NuGet\tools\install.ps1 -recurse + foreach ($build in $builds) { - if ($build.NuGetDir -ne $null) + if ($build.NuGetDir) { $name = $build.TestsName $finalDir = $build.FinalDir diff --git a/Build/install.ps1 b/Build/install.ps1 new file mode 100644 index 00000000..64afd1d8 --- /dev/null +++ b/Build/install.ps1 @@ -0,0 +1,90 @@ +param($installPath, $toolsPath, $package, $project) + +# yolo + +try +{ + $url = "http://www.json.net" + $dte2 = Get-Interface $dte ([EnvDTE80.DTE2]) + + if ($dte2.ActiveWindow.Caption -eq "Package Manager Console") + { + # user is installing from VS NuGet console + # get reference to the window, the console host and the input history + # show webpage if "install-package newtonsoft.json" was last input + + $consoleWindow = $(Get-VSComponentModel).GetService([NuGetConsole.IPowerConsoleWindow]) + + $props = $consoleWindow.GetType().GetProperties([System.Reflection.BindingFlags]::Instance -bor ` + [System.Reflection.BindingFlags]::NonPublic) + + $prop = $props | ? { $_.Name -eq "ActiveHostInfo" } | select -first 1 + if ($prop -eq $null) { return } + + $hostInfo = $prop.GetValue($consoleWindow) + if ($hostInfo -eq $null) { return } + + $history = $hostInfo.WpfConsole.InputHistory.History + + $lastCommand = $history | select -last 1 + + if ($lastCommand) + { + $lastCommand = $lastCommand.Trim().ToLower() + if ($lastCommand.StartsWith("install-package") -and $lastCommand.Contains("newtonsoft.json")) + { + $dte2.ItemOperations.Navigate($url) + } + } + } + else + { + # user is installing from VS NuGet dialog + # get reference to the window, then smart output console provider + # show webpage if messages in buffered console contains "installing...newtonsoft.json" in last operation + + $instanceField = [NuGet.Dialog.PackageManagerWindow].GetField("CurrentInstance", [System.Reflection.BindingFlags]::Static -bor ` + [System.Reflection.BindingFlags]::NonPublic) + $consoleField = [NuGet.Dialog.PackageManagerWindow].GetField("_smartOutputConsoleProvider", [System.Reflection.BindingFlags]::Instance -bor ` + [System.Reflection.BindingFlags]::NonPublic) + if ($instanceField -eq $null -or $consoleField -eq $null) { return } + + $instance = $instanceField.GetValue($null) + if ($instance -eq $null) { return } + + $consoleProvider = $consoleField.GetValue($instance) + if ($consoleProvider -eq $null) { return } + + $console = $consoleProvider.CreateOutputConsole($false) + + $messagesField = $console.GetType().GetField("_messages", [System.Reflection.BindingFlags]::Instance -bor ` + [System.Reflection.BindingFlags]::NonPublic) + if ($messagesField -eq $null) { return } + + $messages = $messagesField.GetValue($console) + if ($messages -eq $null) { return } + + $operations = $messages -split "==============================" + + # second to last + $lastOperation = $operations | select -last 2 | select -first 1 + + if ($lastOperation) + { + $lastOperation = $lastOperation.ToLower() + + $lines = $lastOperation -split "`r`n" + + $installMatch = $lines | ? { $_.StartsWith("------- installing...newtonsoft.json") } | select -first 1 + + if ($installMatch) + { + $dte2.ItemOperations.Navigate($url) + } + } + } +} +catch +{ + # prevent potental errors from bubbling up +} \ No newline at end of file diff --git a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs index 33effc4a..d3b6539f 100644 --- a/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs +++ b/Src/Newtonsoft.Json.Tests/JsonTextReaderTest.cs @@ -47,6 +47,32 @@ namespace Newtonsoft.Json.Tests [TestFixture] public class JsonTextReaderTest : TestFixtureBase { + [Test] + public void ThrowErrorWhenParsingUnquoteStringThatStartsWithNE() + { + const string json = @"{ ""ItemName"": ""value"", ""u"":netanelsalinger,""r"":9 }"; + + JsonTextReader reader = new JsonTextReader(new StringReader(json)); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.StartObject, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.PropertyName, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.String, reader.TokenType); + + Assert.IsTrue(reader.Read()); + Assert.AreEqual(JsonToken.PropertyName, reader.TokenType); + + ExceptionAssert.Throws("Unexpected content while parsing JSON. Path 'u', line 1, position 27.", + () => + { + reader.Read(); + }); + } + [Test] public void FloatParseHandling() { diff --git a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs index 1a6362d5..71b7bed4 100644 --- a/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs +++ b/Src/Newtonsoft.Json.Tests/Linq/LinqToJsonTest.cs @@ -49,6 +49,17 @@ namespace Newtonsoft.Json.Tests.Linq [TestFixture] public class LinqToJsonTest : TestFixtureBase { + [Test] + public void ForEach() + { + JArray items = new JArray(new JObject(new JProperty("name", "value!"))); + + foreach (JObject friend in items) + { + Console.WriteLine(friend); + } + } + [Test] public void DoubleValue() { diff --git a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs index e024fff4..e741406c 100644 --- a/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json.Tests/Properties/AssemblyInfo.cs @@ -75,4 +75,4 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.5.16124")] +[assembly: AssemblyFileVersion("5.0.6.16201")] diff --git a/Src/Newtonsoft.Json/JsonTextReader.cs b/Src/Newtonsoft.Json/JsonTextReader.cs index 5799c317..ddd004b9 100644 --- a/Src/Newtonsoft.Json/JsonTextReader.cs +++ b/Src/Newtonsoft.Json/JsonTextReader.cs @@ -1150,6 +1150,10 @@ namespace Newtonsoft.Json SetToken(JsonToken.StartConstructor, constructorName); } + else + { + throw JsonReaderException.Create(this, "Unexpected content while parsing JSON."); + } } private void ParseNumber() diff --git a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj index 8767f452..f6c8d994 100644 --- a/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj +++ b/Src/Newtonsoft.Json/Newtonsoft.Json.Net35.csproj @@ -5,7 +5,7 @@ AnyCPU 9.0.30729 2.0 - {A9AE40FF-1A21-414A-9FE7-3BE13644CC6D} + {B70AD007-4437-44C2-A25A-6D5AE41691F9} Library Properties Newtonsoft.Json diff --git a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs index 978cc099..3b6044fc 100644 --- a/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs +++ b/Src/Newtonsoft.Json/Properties/AssemblyInfo.cs @@ -92,6 +92,6 @@ using System.Security; // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: [assembly: AssemblyVersion("4.5.0.0")] -[assembly: AssemblyFileVersion("5.0.5.16124")] +[assembly: AssemblyFileVersion("5.0.6.16201")] [assembly: CLSCompliant(true)]