mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Fix bug where strings that looked like dates were transformed when reading messages (#663)
* Do not try to parse dates when reading messages * Add test
This commit is contained in:
committed by
Karl Burtram
parent
a289deded5
commit
c7ac3aeaae
@@ -12,6 +12,7 @@ using Microsoft.SqlTools.Hosting;
|
|||||||
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
using Microsoft.SqlTools.Hosting.Protocol.Contracts;
|
||||||
using Microsoft.SqlTools.Hosting.Protocol.Serializers;
|
using Microsoft.SqlTools.Hosting.Protocol.Serializers;
|
||||||
using Microsoft.SqlTools.Utility;
|
using Microsoft.SqlTools.Utility;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.Hosting.Protocol
|
namespace Microsoft.SqlTools.Hosting.Protocol
|
||||||
@@ -110,7 +111,9 @@ namespace Microsoft.SqlTools.Hosting.Protocol
|
|||||||
ShiftBufferBytesAndShrink(readOffset);
|
ShiftBufferBytesAndShrink(readOffset);
|
||||||
|
|
||||||
// Get the JObject for the JSON content
|
// Get the JObject for the JSON content
|
||||||
JObject messageObject = JObject.Parse(messageContent);
|
JsonReader messageReader = new JsonTextReader(new StringReader(messageContent));
|
||||||
|
messageReader.DateParseHandling = DateParseHandling.None;
|
||||||
|
JObject messageObject = JObject.Load(messageReader);
|
||||||
|
|
||||||
// Return the parsed message
|
// Return the parsed message
|
||||||
return this.messageSerializer.DeserializeMessage(messageObject);
|
return this.messageSerializer.DeserializeMessage(messageObject);
|
||||||
|
|||||||
@@ -220,6 +220,31 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Messaging
|
|||||||
inputStream.Dispose();
|
inputStream.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ReaderDoesNotModifyDateStrings()
|
||||||
|
{
|
||||||
|
MemoryStream inputStream = new MemoryStream();
|
||||||
|
MessageReader messageReader =
|
||||||
|
new MessageReader(
|
||||||
|
inputStream,
|
||||||
|
this.messageSerializer);
|
||||||
|
|
||||||
|
string dateString = "2018-04-27T18:33:55.870Z";
|
||||||
|
|
||||||
|
// Get a message with content that is a date as a string
|
||||||
|
byte[] messageBuffer = this.GetMessageBytes(
|
||||||
|
string.Format(Common.TestEventFormatString, dateString));
|
||||||
|
|
||||||
|
inputStream.Write(messageBuffer, 0, messageBuffer.Length);
|
||||||
|
inputStream.Flush();
|
||||||
|
inputStream.Seek(0, SeekOrigin.Begin);
|
||||||
|
|
||||||
|
Message messageResult = messageReader.ReadMessage().Result;
|
||||||
|
Assert.Equal(dateString, messageResult.Contents.Value<string>("someString"));
|
||||||
|
|
||||||
|
inputStream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
private byte[] GetMessageBytes(string messageString, Encoding encoding = null)
|
private byte[] GetMessageBytes(string messageString, Encoding encoding = null)
|
||||||
{
|
{
|
||||||
if (encoding == null)
|
if (encoding == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user