Skip to content

Commit

Permalink
Convert.ToDouble fix for non-english locales #8
Browse files Browse the repository at this point in the history
  • Loading branch information
artema committed Nov 29, 2015
1 parent 0059497 commit 9d0f0c2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Src/DotAmf/Decoder/AmfPacketDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AmfPacketDecoder(AmfEncodingOptions options)
/// <summary>
/// Decode an AMF packet into an AMFX format.
/// </summary>
/// <exception cref="InvalidDataException">Error during decoding.</exception>
/// <exception cref="FormatException">Error during decoding.</exception>
public void Decode(Stream stream, XmlWriter output)
{
if (stream == null) throw new ArgumentNullException("stream");
Expand Down Expand Up @@ -97,7 +97,7 @@ public void Decode(Stream stream, XmlWriter output)
catch (Exception e)
{
output.Flush();
throw new InvalidDataException(Errors.AmfPacketReader_DecodingError, e);
throw new FormatException(Errors.AmfPacketReader_DecodingError, e);
}
}
#endregion
Expand Down
Binary file modified Src/DotAmf/DotAmf.nupkg
Binary file not shown.
15 changes: 8 additions & 7 deletions Src/DotAmf/Encoder/Amf3Encoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Xml;
using DotAmf.Data;
using DotAmf.IO;
using System.Globalization;

namespace DotAmf.Encoder
{
Expand Down Expand Up @@ -244,7 +245,7 @@ protected override void WriteAmfValue(AmfContext context, XmlReader input, AmfSt
/// </summary>
private static void WriteReference(AmfContext context, AmfStreamWriter writer, XmlReader input)
{
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.ReferenceId));
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.ReferenceId), CultureInfo.InvariantCulture);
var proxy = context.References[index];

switch(proxy.AmfxType)
Expand Down Expand Up @@ -282,7 +283,7 @@ private static void WriteReference(AmfContext context, AmfStreamWriter writer, X
private static void WriteInteger(AmfStreamWriter writer, XmlReader input)
{
input.Read();
var value = Convert.ToInt32(input.Value);
var value = Convert.ToInt32(input.Value, CultureInfo.InvariantCulture);
input.Read();

//Check if the value fits the Int29 span
Expand All @@ -298,7 +299,7 @@ private static void WriteInteger(AmfStreamWriter writer, XmlReader input)
else
{
WriteTypeMarker(writer, Amf3TypeMarker.Double);
writer.Write(Convert.ToDouble(value));
writer.Write(Convert.ToDouble(value, CultureInfo.InvariantCulture));
}
}

Expand All @@ -308,7 +309,7 @@ private static void WriteInteger(AmfStreamWriter writer, XmlReader input)
private static void WriteDouble(AmfStreamWriter writer, XmlReader input)
{
input.Read();
var value = Convert.ToDouble(input.Value);
var value = Convert.ToDouble(input.Value, CultureInfo.InvariantCulture);
input.Read();

WriteTypeMarker(writer, Amf3TypeMarker.Double);
Expand All @@ -328,7 +329,7 @@ private static void WriteString(AmfContext context, AmfStreamWriter writer, XmlR
{
if (input.AttributeCount > 0)
{
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.StringId));
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.StringId), CultureInfo.InvariantCulture);
WriteReference(writer, index);
return;
}
Expand Down Expand Up @@ -412,7 +413,7 @@ private void WriteArray(AmfContext context, AmfStreamWriter writer, XmlReader in
context.References.Add(new AmfReference { AmfxType = AmfxContent.Array });
WriteTypeMarker(writer, Amf3TypeMarker.Array);

var length = Convert.ToInt32(input.GetAttribute(AmfxContent.ArrayLength));
var length = Convert.ToInt32(input.GetAttribute(AmfxContent.ArrayLength), CultureInfo.InvariantCulture);

//The first bit is a flag with value 1.
//The remaining 1 to 28 significant bits
Expand Down Expand Up @@ -495,7 +496,7 @@ private void WriteObject(AmfContext context, AmfStreamWriter writer, XmlReader i
//Send traits by reference
else
{
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.TraitsId));
var index = Convert.ToInt32(input.GetAttribute(AmfxContent.TraitsId), CultureInfo.InvariantCulture);
traits = context.TraitsReferences[index];

var flag = index & UInt29Mask; //Truncate value to UInt29
Expand Down
4 changes: 2 additions & 2 deletions Src/DotAmf/Encoder/AmfPacketEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public AmfPacketEncoder(AmfEncodingOptions options)
/// <summary>
/// Encode an AMF packet from an AMFX format.
/// </summary>
/// <exception cref="InvalidDataException">Error during encoding.</exception>
/// <exception cref="FormatException">Error during encoding.</exception>
public void Encode(Stream stream, XmlReader input)
{
if (stream == null) throw new ArgumentNullException("stream");
Expand Down Expand Up @@ -128,7 +128,7 @@ public void Encode(Stream stream, XmlReader input)
}
catch (Exception e)
{
throw new InvalidDataException(Errors.AmfPacketReader_DecodingError, e);
throw new FormatException(Errors.AmfPacketReader_DecodingError, e);
}
}
#endregion
Expand Down

0 comments on commit 9d0f0c2

Please sign in to comment.