From bb7cf250050d26753617c5163b2c64cd83d42729 Mon Sep 17 00:00:00 2001 From: Effy Teva Date: Sun, 16 Dec 2018 16:39:18 +0200 Subject: [PATCH 1/2] Missing InvariantCulture on Parse methods --- EntityFramework/src/ProviderServices.cs | 2 +- MySQL.Data/src/Driver.cs | 2 +- MySQL.Data/src/ISSchemaProvider.cs | 6 +- MySQL.Data/src/SchemaProvider.cs | 2 +- MySQL.Data/src/Types/MySqlBit.cs | 3 +- MySQL.Data/src/Types/MySqlDateTime.cs | 14 +-- MySQL.Data/src/Types/MySqlDecimal.cs | 2 +- MySQL.Data/src/Types/MySqlInt16.cs | 3 +- MySQL.Data/src/Types/MySqlInt64.cs | 3 +- MySQL.Data/src/Types/MySqlTime.cs | 9 +- MySQL.Data/src/Types/MySqlUByte.cs | 3 +- MySQL.Data/src/Types/MySqlUInt16.cs | 3 +- MySQL.Data/src/Types/MySqlUInt64.cs | 3 +- MySQL.Data/src/X/Protocol/X/DecimalDecoder.cs | 103 +++++++++--------- MySQL.Data/src/X/Protocol/X/ExprParser.cs | 7 +- .../src/PersonalizationProviderProcedures.cs | 15 +-- MySql.Web/src/SimpleMembershipProvider.cs | 9 +- MySql.Web/src/SimpleRoleProvider.cs | 9 +- 18 files changed, 105 insertions(+), 93 deletions(-) diff --git a/EntityFramework/src/ProviderServices.cs b/EntityFramework/src/ProviderServices.cs index cf06a806..0468632b 100644 --- a/EntityFramework/src/ProviderServices.cs +++ b/EntityFramework/src/ProviderServices.cs @@ -56,7 +56,7 @@ public string GetTableCreateScript(EntitySet entitySet, string connectionString, using (var conn = new MySqlConnection(connectionString.Replace(@"""", ""))) { conn.Open(); - var v = DBVersion.Parse(conn.ServerVersion.ToString()); + var v = DBVersion.Parse(conn.ServerVersion.ToString()); service.serverVersion = new Version(v.Major + "." + v.Minor); } } diff --git a/MySQL.Data/src/Driver.cs b/MySQL.Data/src/Driver.cs index faaf85ce..d4feb0b7 100644 --- a/MySQL.Data/src/Driver.cs +++ b/MySQL.Data/src/Driver.cs @@ -321,7 +321,7 @@ private int GetTimeZoneOffset(MySqlConnection con ) if (timeZoneDiff.HasValue) timeZoneString = timeZoneDiff.ToString(); - return int.Parse(timeZoneString.Substring(0, timeZoneString.IndexOf(':'))); + return int.Parse(timeZoneString.Substring(0, timeZoneString.IndexOf(':')), CultureInfo.InvariantCulture); } /// diff --git a/MySQL.Data/src/ISSchemaProvider.cs b/MySQL.Data/src/ISSchemaProvider.cs index 40f01260..b4637057 100644 --- a/MySQL.Data/src/ISSchemaProvider.cs +++ b/MySQL.Data/src/ISSchemaProvider.cs @@ -717,14 +717,14 @@ private static void ParseDataTypeSize(MySqlSchemaRow row, string size) if (!MetaData.IsNumericType(row["DATA_TYPE"].ToString())) { - row["CHARACTER_MAXIMUM_LENGTH"] = Int32.Parse(parts[0]); + row["CHARACTER_MAXIMUM_LENGTH"] = Int32.Parse(parts[0], CultureInfo.InvariantCulture); // will set octet length in a minute } else { - row["NUMERIC_PRECISION"] = Int32.Parse(parts[0]); + row["NUMERIC_PRECISION"] = Int32.Parse(parts[0], CultureInfo.InvariantCulture); if (parts.Length == 2) - row["NUMERIC_SCALE"] = Int32.Parse(parts[1]); + row["NUMERIC_SCALE"] = Int32.Parse(parts[1], CultureInfo.InvariantCulture); } } diff --git a/MySQL.Data/src/SchemaProvider.cs b/MySQL.Data/src/SchemaProvider.cs index 5ad6485f..801b5e1e 100644 --- a/MySQL.Data/src/SchemaProvider.cs +++ b/MySQL.Data/src/SchemaProvider.cs @@ -67,7 +67,7 @@ public virtual MySqlSchemaCollection GetSchema(string collection, String[] restr public virtual MySqlSchemaCollection GetDatabases(string[] restrictions) { Regex regex = null; - int caseSetting = Int32.Parse(connection.driver.Property("lower_case_table_names")); + int caseSetting = Int32.Parse(connection.driver.Property("lower_case_table_names"), CultureInfo.InvariantCulture); string sql = "SHOW DATABASES"; diff --git a/MySQL.Data/src/Types/MySqlBit.cs b/MySQL.Data/src/Types/MySqlBit.cs index b61915e2..119d55b0 100644 --- a/MySQL.Data/src/Types/MySqlBit.cs +++ b/MySQL.Data/src/Types/MySqlBit.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -76,7 +77,7 @@ public IMySqlValue ReadValue(MySqlPacket packet, long length, bool isNull) length = packet.ReadFieldLength(); if (ReadAsString) - _value = UInt64.Parse(packet.ReadString(length)); + _value = UInt64.Parse(packet.ReadString(length), CultureInfo.InvariantCulture); else _value = (UInt64)packet.ReadBitValue((int)length); return this; diff --git a/MySQL.Data/src/Types/MySqlDateTime.cs b/MySQL.Data/src/Types/MySqlDateTime.cs index 9dc6ee45..f5e36848 100644 --- a/MySQL.Data/src/Types/MySqlDateTime.cs +++ b/MySQL.Data/src/Types/MySqlDateTime.cs @@ -309,21 +309,21 @@ private MySqlDateTime ParseMySql(string s) { string[] parts = s.Split('-', ' ', ':', '/', '.'); - int year = int.Parse(parts[0]); - int month = int.Parse(parts[1]); - int day = int.Parse(parts[2]); + int year = int.Parse(parts[0], CultureInfo.InvariantCulture); + int month = int.Parse(parts[1], CultureInfo.InvariantCulture); + int day = int.Parse(parts[2], CultureInfo.InvariantCulture); int hour = 0, minute = 0, second = 0, microsecond = 0; if (parts.Length > 3) { - hour = int.Parse(parts[3]); - minute = int.Parse(parts[4]); - second = int.Parse(parts[5]); + hour = int.Parse(parts[3], CultureInfo.InvariantCulture); + minute = int.Parse(parts[4], CultureInfo.InvariantCulture); + second = int.Parse(parts[5], CultureInfo.InvariantCulture); } if (parts.Length > 6) { - microsecond = int.Parse(parts[6].PadRight(6, '0')); + microsecond = int.Parse(parts[6].PadRight(6, '0'), CultureInfo.InvariantCulture); } return new MySqlDateTime(_type, year, month, day, hour, minute, second, microsecond); diff --git a/MySQL.Data/src/Types/MySqlDecimal.cs b/MySQL.Data/src/Types/MySqlDecimal.cs index 23001f8a..6c9d4a27 100644 --- a/MySQL.Data/src/Types/MySqlDecimal.cs +++ b/MySQL.Data/src/Types/MySqlDecimal.cs @@ -86,7 +86,7 @@ internal MySqlDecimal(string val) /// The value of this type converted to a dobule value. public double ToDouble() { - return Double.Parse(_value); + return Double.Parse(_value, CultureInfo.InvariantCulture); } public override string ToString() diff --git a/MySQL.Data/src/Types/MySqlInt16.cs b/MySQL.Data/src/Types/MySqlInt16.cs index e8bc0a45..6c8f5a64 100644 --- a/MySQL.Data/src/Types/MySqlInt16.cs +++ b/MySQL.Data/src/Types/MySqlInt16.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -76,7 +77,7 @@ IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) if (length == -1) return new MySqlInt16((short)packet.ReadInteger(2)); else - return new MySqlInt16(Int16.Parse(packet.ReadString(length))); + return new MySqlInt16(Int16.Parse(packet.ReadString(length), CultureInfo.InvariantCulture)); } void IMySqlValue.SkipValue(MySqlPacket packet) diff --git a/MySQL.Data/src/Types/MySqlInt64.cs b/MySQL.Data/src/Types/MySqlInt64.cs index 280e8132..114f7a8d 100644 --- a/MySQL.Data/src/Types/MySqlInt64.cs +++ b/MySQL.Data/src/Types/MySqlInt64.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -79,7 +80,7 @@ IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) if (length == -1) return new MySqlInt64((long)packet.ReadULong(8)); else - return new MySqlInt64(Int64.Parse(packet.ReadString(length))); + return new MySqlInt64(Int64.Parse(packet.ReadString(length), CultureInfo.InvariantCulture)); } void IMySqlValue.SkipValue(MySqlPacket packet) diff --git a/MySQL.Data/src/Types/MySqlTime.cs b/MySQL.Data/src/Types/MySqlTime.cs index 84eefa84..5cfb98d0 100644 --- a/MySQL.Data/src/Types/MySqlTime.cs +++ b/MySQL.Data/src/Types/MySqlTime.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -177,16 +178,16 @@ private void ParseMySql(string s) { string[] parts = s.Split(':', '.'); - int hours = Int32.Parse(parts[0]); - int mins = Int32.Parse(parts[1]); - int secs = Int32.Parse(parts[2]); + int hours = Int32.Parse(parts[0], CultureInfo.InvariantCulture); + int mins = Int32.Parse(parts[1], CultureInfo.InvariantCulture); + int secs = Int32.Parse(parts[2], CultureInfo.InvariantCulture); int nanoseconds = 0; if (parts.Length > 3) { //if the data is saved in MySql as Time(3) the division by 1000 always returns 0, but handling the data as Time(6) the result is the expected parts[3] = parts[3].PadRight(7, '0'); - nanoseconds = int.Parse(parts[3]); + nanoseconds = int.Parse(parts[3], CultureInfo.InvariantCulture); } diff --git a/MySQL.Data/src/Types/MySqlUByte.cs b/MySQL.Data/src/Types/MySqlUByte.cs index 783460fc..63d75098 100644 --- a/MySQL.Data/src/Types/MySqlUByte.cs +++ b/MySQL.Data/src/Types/MySqlUByte.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -76,7 +77,7 @@ IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) if (length == -1) return new MySqlUByte((byte)packet.ReadByte()); else - return new MySqlUByte(Byte.Parse(packet.ReadString(length))); + return new MySqlUByte(Byte.Parse(packet.ReadString(length), CultureInfo.InvariantCulture)); } void IMySqlValue.SkipValue(MySqlPacket packet) diff --git a/MySQL.Data/src/Types/MySqlUInt16.cs b/MySQL.Data/src/Types/MySqlUInt16.cs index 1a5a67ee..8926a00a 100644 --- a/MySQL.Data/src/Types/MySqlUInt16.cs +++ b/MySQL.Data/src/Types/MySqlUInt16.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -76,7 +77,7 @@ IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) if (length == -1) return new MySqlUInt16((ushort)packet.ReadInteger(2)); else - return new MySqlUInt16(UInt16.Parse(packet.ReadString(length))); + return new MySqlUInt16(UInt16.Parse(packet.ReadString(length), CultureInfo.InvariantCulture)); } void IMySqlValue.SkipValue(MySqlPacket packet) diff --git a/MySQL.Data/src/Types/MySqlUInt64.cs b/MySQL.Data/src/Types/MySqlUInt64.cs index 85c72a6f..55e0a542 100644 --- a/MySQL.Data/src/Types/MySqlUInt64.cs +++ b/MySQL.Data/src/Types/MySqlUInt64.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Data.Types @@ -79,7 +80,7 @@ IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) if (length == -1) return new MySqlUInt64(packet.ReadULong(8)); else - return new MySqlUInt64(UInt64.Parse(packet.ReadString(length))); + return new MySqlUInt64(UInt64.Parse(packet.ReadString(length), CultureInfo.InvariantCulture)); } void IMySqlValue.SkipValue(MySqlPacket packet) diff --git a/MySQL.Data/src/X/Protocol/X/DecimalDecoder.cs b/MySQL.Data/src/X/Protocol/X/DecimalDecoder.cs index 850cdb6f..d883a9bb 100644 --- a/MySQL.Data/src/X/Protocol/X/DecimalDecoder.cs +++ b/MySQL.Data/src/X/Protocol/X/DecimalDecoder.cs @@ -26,56 +26,57 @@ // along with this program; if not, write to the Free Software Foundation, Inc., // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -using MySql.Data; -using MySql.Data.MySqlClient.X.XDevAPI.Common; + +using MySql.Data; +using MySql.Data.MySqlClient.X.XDevAPI.Common; using MySqlX.Data; -using System; - -namespace MySqlX.Protocol.X -{ - internal class DecimalDecoder : ValueDecoder - { - public override void SetMetadata() - { - Column.Type = ColumnType.Decimal; - Column.ClrType = typeof(decimal); - ClrValueDecoder = DecimalValueDecoder; - } - - private object DecimalValueDecoder(byte[] bytes) - { - // this decoder is based on the BCD standard - int scale = bytes[0]; - byte sign = bytes[bytes.Length - 1]; - string stringValue = string.Empty; - string lastDigit = string.Empty; - - if (sign == 0xc0) - stringValue = "+"; - else if (sign == 0xd0) - stringValue = "-"; - else if((sign & 0x0F) == 0x0c) - { - stringValue = "+"; - lastDigit = (sign >> 4).ToString(); - } - else if((sign & 0x0F) == 0x0d) - { - stringValue = "-"; - lastDigit = (sign >> 4).ToString(); - } - else - throw new FormatException(ResourcesX.InvalidDecimalFormat); - - for(int i = 1; i < bytes.Length - 1; i++) - { - stringValue += bytes[i].ToString("x2"); - } - stringValue += lastDigit; - stringValue = stringValue.Insert(stringValue.Length - scale, "."); - - return Decimal.Parse(stringValue); - } - } +using System; +using System.Globalization; + +namespace MySqlX.Protocol.X +{ + internal class DecimalDecoder : ValueDecoder + { + public override void SetMetadata() + { + Column.Type = ColumnType.Decimal; + Column.ClrType = typeof(decimal); + ClrValueDecoder = DecimalValueDecoder; + } + + private object DecimalValueDecoder(byte[] bytes) + { + // this decoder is based on the BCD standard + int scale = bytes[0]; + byte sign = bytes[bytes.Length - 1]; + string stringValue = string.Empty; + string lastDigit = string.Empty; + + if (sign == 0xc0) + stringValue = "+"; + else if (sign == 0xd0) + stringValue = "-"; + else if((sign & 0x0F) == 0x0c) + { + stringValue = "+"; + lastDigit = (sign >> 4).ToString(); + } + else if((sign & 0x0F) == 0x0d) + { + stringValue = "-"; + lastDigit = (sign >> 4).ToString(); + } + else + throw new FormatException(ResourcesX.InvalidDecimalFormat); + + for(int i = 1; i < bytes.Length - 1; i++) + { + stringValue += bytes[i].ToString("x2"); + } + stringValue += lastDigit; + stringValue = stringValue.Insert(stringValue.Length - scale, "."); + + return Decimal.Parse(stringValue, CultureInfo.InvariantCulture); + } + } } \ No newline at end of file diff --git a/MySQL.Data/src/X/Protocol/X/ExprParser.cs b/MySQL.Data/src/X/Protocol/X/ExprParser.cs index 85345fdb..3be19055 100644 --- a/MySQL.Data/src/X/Protocol/X/ExprParser.cs +++ b/MySQL.Data/src/X/Protocol/X/ExprParser.cs @@ -30,6 +30,7 @@ using Mysqlx.Expr; using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Text; @@ -676,7 +677,7 @@ DocumentPathItem DocPathArrayLoc() } else if (CurrentTokenTypeEquals(TokenType.LNUM_INT)) { - uint v = uint.Parse(this.tokens[this.tokenPos].value); + uint v = uint.Parse(this.tokens[this.tokenPos].value, CultureInfo.InvariantCulture); if (v < 0) { throw new ArgumentException("Array index cannot be negative at " + this.tokenPos); @@ -966,9 +967,9 @@ Expr AtomicExpr() case TokenType.NULL: return ExprUtil.BuildLiteralNullScalar(); case TokenType.LNUM_INT: - return ExprUtil.BuildLiteralScalar(long.Parse(t.value)); + return ExprUtil.BuildLiteralScalar(long.Parse(t.value, CultureInfo.InvariantCulture)); case TokenType.LNUM_DOUBLE: - return ExprUtil.BuildLiteralScalar(double.Parse(t.value)); + return ExprUtil.BuildLiteralScalar(double.Parse(t.value, CultureInfo.InvariantCulture)); case TokenType.TRUE: case TokenType.FALSE: return ExprUtil.BuildLiteralScalar(t.type == TokenType.TRUE); diff --git a/MySql.Web/src/PersonalizationProviderProcedures.cs b/MySql.Web/src/PersonalizationProviderProcedures.cs index d7a93981..3590b598 100644 --- a/MySql.Web/src/PersonalizationProviderProcedures.cs +++ b/MySql.Web/src/PersonalizationProviderProcedures.cs @@ -27,6 +27,7 @@ // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA using System; +using System.Globalization; using MySql.Data.MySqlClient; namespace MySql.Web.Personalization @@ -167,7 +168,7 @@ internal class PersonalizationProviderProcedures findStateCommand.Parameters.AddWithValue("@PageLowerBound", pageLowerBound); findStateCommand.Connection = connection.Connection; - return int.Parse(totalRecords); + return int.Parse(totalRecords, CultureInfo.InvariantCulture); } } @@ -192,7 +193,7 @@ internal static int myaspnet_PersonalizationAdministration_GetCountOfState(bool cmd.Parameters.AddWithValue("@Path", path); cmd.Connection = connection.Connection; var count = cmd.ExecuteScalar().ToString(); - return int.Parse(count); + return int.Parse(count, CultureInfo.InvariantCulture); } else { MySqlCommand cmd = new MySqlCommand("Select count(*) from my_aspnet_personalizationperuser as peruser, my_aspnet_users as users, "+ @@ -210,7 +211,7 @@ internal static int myaspnet_PersonalizationAdministration_GetCountOfState(bool cmd.Parameters.AddWithValue("@InactiveSinceDate", inactiveSinceDate); cmd.Connection = connection.Connection; var count = cmd.ExecuteScalar().ToString(); - return int.Parse(count); + return int.Parse(count, CultureInfo.InvariantCulture); } } @@ -244,10 +245,10 @@ internal static Byte[] my_aspnet_PersonalizationPerUser_GetPageSettings(long app var userId = (cmd.ExecuteScalar() ?? "").ToString(); userId = string.IsNullOrEmpty(userId) ? "0" : userId; - if (int.Parse(userId) == 0) + if (int.Parse(userId, CultureInfo.InvariantCulture) == 0) return null; - UpdateUserLastActiveDate(connection.Connection, int.Parse(userId), currentTimeUtc); + UpdateUserLastActiveDate(connection.Connection, int.Parse(userId, CultureInfo.InvariantCulture), currentTimeUtc); cmd = new MySqlCommand("select pagesettings from my_aspnet_personalizationperuser as peruser where peruser.pathid = @PathId and peruser.userid = @UserId"); cmd.Connection = connection.Connection; @@ -576,7 +577,7 @@ internal static int my_aspnet_PersonalizationPerUser_SetPageSettings(long applic userId = string.IsNullOrEmpty(userId) ? "0" : userId; // create user - if (int.Parse(userId) == 0) + if (int.Parse(userId, CultureInfo.InvariantCulture) == 0) { // create path MySqlTransaction trans; @@ -606,7 +607,7 @@ internal static int my_aspnet_PersonalizationPerUser_SetPageSettings(long applic userId = (string)cmd.ExecuteScalar(); } - var rows = UpdateUserLastActiveDate(connection.Connection, int.Parse(userId), DateTime.UtcNow); + var rows = UpdateUserLastActiveDate(connection.Connection, int.Parse(userId, CultureInfo.InvariantCulture), DateTime.UtcNow); if (rows == 0) throw new Exception("User not found"); diff --git a/MySql.Web/src/SimpleMembershipProvider.cs b/MySql.Web/src/SimpleMembershipProvider.cs index 60329442..7ca68d3a 100644 --- a/MySql.Web/src/SimpleMembershipProvider.cs +++ b/MySql.Web/src/SimpleMembershipProvider.cs @@ -32,6 +32,7 @@ using System.Collections.Generic; using System.Configuration; using System.Configuration.Provider; +using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -111,10 +112,10 @@ public override void Initialize(string name, System.Collections.Specialized.Name base.Initialize(name, config); var appName = GetConfigValue(config["applicationName"], HostingEnvironment.SiteName); - _maxPwdAttempts = Int32.Parse(GetConfigValue(config["maxInvalidPasswordAttempts"], "5")); - _pwdAttemptWindow = Int32.Parse(GetConfigValue(config["passwordAttemptWindow"], "10")); - _minReqNonAlphanumericalChars = Int32.Parse(GetConfigValue(config["minRequiredNonalphanumericCharacters"], "1")); - _minReqPwdLength = Int32.Parse(GetConfigValue(config["minRequiredPasswordLength"], "7")); + _maxPwdAttempts = Int32.Parse(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"), CultureInfo.InvariantCulture); + _pwdAttemptWindow = Int32.Parse(GetConfigValue(config["passwordAttemptWindow"], "10"), CultureInfo.InvariantCulture); + _minReqNonAlphanumericalChars = Int32.Parse(GetConfigValue(config["minRequiredNonalphanumericCharacters"], "1"), CultureInfo.InvariantCulture); + _minReqPwdLength = Int32.Parse(GetConfigValue(config["minRequiredPasswordLength"], "7"), CultureInfo.InvariantCulture); _pwdStrenghtRegex = GetConfigValue(config["passwordStrengthRegularExpression"], ""); _enablePwdReset = bool.Parse(GetConfigValue(config["enablePasswordReset"], "True")); _enablePwdRetrival = bool.Parse(GetConfigValue(config["enablePasswordRetrieval"], "False")); diff --git a/MySql.Web/src/SimpleRoleProvider.cs b/MySql.Web/src/SimpleRoleProvider.cs index 022ccb6d..e7983a76 100644 --- a/MySql.Web/src/SimpleRoleProvider.cs +++ b/MySql.Web/src/SimpleRoleProvider.cs @@ -32,6 +32,7 @@ using System; using System.Collections.Generic; using System.Configuration.Provider; +using System.Globalization; using System.Linq; using System.Resources; using System.Web.Hosting; @@ -104,10 +105,10 @@ public override void Initialize(string name, System.Collections.Specialized.Name base.Initialize(name, config); var appName = GetConfigValue(config["applicationName"], HostingEnvironment.SiteName); - _maxPwdAttempts = Int32.Parse(GetConfigValue(config["maxInvalidPasswordAttempts"], "5")); - _pwdAttemptWindow = Int32.Parse(GetConfigValue(config["passwordAttemptWindow"], "10")); - _minReqNonAlphanumericalChars = Int32.Parse(GetConfigValue(config["minRequiredNonalphanumericCharacters"], "1")); - _minReqPwdLength = Int32.Parse(GetConfigValue(config["minRequiredPasswordLength"], "7")); + _maxPwdAttempts = Int32.Parse(GetConfigValue(config["maxInvalidPasswordAttempts"], "5"), CultureInfo.InvariantCulture); + _pwdAttemptWindow = Int32.Parse(GetConfigValue(config["passwordAttemptWindow"], "10"), CultureInfo.InvariantCulture); + _minReqNonAlphanumericalChars = Int32.Parse(GetConfigValue(config["minRequiredNonalphanumericCharacters"], "1"), CultureInfo.InvariantCulture); + _minReqPwdLength = Int32.Parse(GetConfigValue(config["minRequiredPasswordLength"], "7"), CultureInfo.InvariantCulture); _pwdStrenghtRegex = GetConfigValue(config["passwordStrengthRegularExpression"], ""); _enablePwdReset = bool.Parse(GetConfigValue(config["enablePasswordReset"], "True")); _enablePwdRetrival = bool.Parse(GetConfigValue(config["enablePasswordRetrieval"], "False")); From 3ddb04ad886fa0b3b71f14023f6235418aeed709 Mon Sep 17 00:00:00 2001 From: Effy Teva Date: Sun, 16 Dec 2018 17:35:36 +0200 Subject: [PATCH 2/2] Missing InvariantCulture --- MySQL.Data/src/MySqlBaseConnectionStringBuilder.cs | 10 +++++----- MySQL.Data/src/MysqlDefs.cs | 5 +++-- MySQL.Data/src/Types/MySqlBit.cs | 4 ++-- MySQL.Data/src/Types/MySqlByte.cs | 2 +- MySQL.Data/src/Types/MySqlDateTime.cs | 2 +- MySQL.Data/src/Types/MySqlInt16.cs | 2 +- MySQL.Data/src/Types/MySqlInt32.cs | 4 ++-- MySQL.Data/src/Types/MySqlInt64.cs | 2 +- MySQL.Data/src/Types/MySqlSingle.cs | 3 +-- MySQL.Data/src/Types/MySqlUByte.cs | 2 +- MySQL.Data/src/Types/MySqlUInt16.cs | 4 ++-- MySQL.Data/src/Types/MySqlUInt32.cs | 2 +- MySQL.Data/src/Types/MySqlUInt64.cs | 2 +- 13 files changed, 22 insertions(+), 22 deletions(-) diff --git a/MySQL.Data/src/MySqlBaseConnectionStringBuilder.cs b/MySQL.Data/src/MySqlBaseConnectionStringBuilder.cs index d0c46d14..0d4b3493 100644 --- a/MySQL.Data/src/MySqlBaseConnectionStringBuilder.cs +++ b/MySQL.Data/src/MySqlBaseConnectionStringBuilder.cs @@ -637,16 +637,16 @@ public void ValidateValue(ref object value) if (typeName == "Boolean" && Boolean.TryParse(value.ToString(), out b)) { value = b; return; } UInt64 uintVal; - if (typeName.StartsWith("UInt64") && UInt64.TryParse(value.ToString(), out uintVal)) { value = uintVal; return; } + if (typeName.StartsWith("UInt64") && UInt64.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out uintVal)) { value = uintVal; return; } UInt32 uintVal32; - if (typeName.StartsWith("UInt32") && UInt32.TryParse(value.ToString(), out uintVal32)) { value = uintVal32; return; } + if (typeName.StartsWith("UInt32") && UInt32.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out uintVal32)) { value = uintVal32; return; } Int64 intVal; - if (typeName.StartsWith("Int64") && Int64.TryParse(value.ToString(), out intVal)) { value = intVal; return; } + if (typeName.StartsWith("Int64") && Int64.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out intVal)) { value = intVal; return; } Int32 intVal32; - if (typeName.StartsWith("Int32") && Int32.TryParse(value.ToString(), out intVal32)) { value = intVal32; return; } + if (typeName.StartsWith("Int32") && Int32.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out intVal32)) { value = intVal32; return; } object objValue; Type baseType = BaseType.GetTypeInfo().BaseType; @@ -666,7 +666,7 @@ public void ValidateValue(ref object value, string keyword) switch (keyword) { case "connect-timeout": - if (typeName != valueType.Name && !uint.TryParse(value.ToString(), out uint uintVal)) throw new FormatException(ResourcesX.InvalidConnectionTimeoutValue); + if (typeName != valueType.Name && !uint.TryParse(value.ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out uint uintVal)) throw new FormatException(ResourcesX.InvalidConnectionTimeoutValue); break; } } diff --git a/MySQL.Data/src/MysqlDefs.cs b/MySQL.Data/src/MysqlDefs.cs index 8882a768..3a920a6b 100644 --- a/MySQL.Data/src/MysqlDefs.cs +++ b/MySQL.Data/src/MysqlDefs.cs @@ -28,6 +28,7 @@ using System; using System.ComponentModel; +using System.Globalization; using System.Reflection; namespace MySql.Data.MySqlClient @@ -530,7 +531,7 @@ public string PID string pid = string.Empty; try { - pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); + pid = System.Diagnostics.Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture); } catch (Exception ex) { @@ -561,7 +562,7 @@ public string Thread string thread = string.Empty; try { - thread = System.Diagnostics.Process.GetCurrentProcess().Threads[0].Id.ToString(); + thread = System.Diagnostics.Process.GetCurrentProcess().Threads[0].Id.ToString(CultureInfo.InvariantCulture); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } diff --git a/MySQL.Data/src/Types/MySqlBit.cs b/MySQL.Data/src/Types/MySqlBit.cs index 119d55b0..64e7432e 100644 --- a/MySQL.Data/src/Types/MySqlBit.cs +++ b/MySQL.Data/src/Types/MySqlBit.cs @@ -64,7 +64,7 @@ public void WriteValue(MySqlPacket packet, bool binary, object value, int length if (binary) packet.WriteInteger((long)v, 8); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } public IMySqlValue ReadValue(MySqlPacket packet, long length, bool isNull) @@ -99,7 +99,7 @@ internal static void SetDSInfo(MySqlSchemaCollection sc) row["ProviderDbType"] = MySqlDbType.Bit; row["ColumnSize"] = 64; row["CreateFormat"] = "BIT"; - row["CreateParameters"] = DBNull.Value; ; + row["CreateParameters"] = DBNull.Value; row["DataType"] = typeof(ulong).ToString(); row["IsAutoincrementable"] = false; row["IsBestMatch"] = true; diff --git a/MySQL.Data/src/Types/MySqlByte.cs b/MySQL.Data/src/Types/MySqlByte.cs index 6b00f70b..5f8d6839 100644 --- a/MySQL.Data/src/Types/MySqlByte.cs +++ b/MySQL.Data/src/Types/MySqlByte.cs @@ -76,7 +76,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.WriteByte((byte)v); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlDateTime.cs b/MySQL.Data/src/Types/MySqlDateTime.cs index f5e36848..1f1f0090 100644 --- a/MySQL.Data/src/Types/MySqlDateTime.cs +++ b/MySQL.Data/src/Types/MySqlDateTime.cs @@ -415,7 +415,7 @@ public override string ToString() if (this.IsValidDateTime) { DateTime d = new DateTime(Year, Month, Day, Hour, Minute, Second).AddTicks(_microsecond * 10); - return (_type == MySqlDbType.Date) ? d.ToString("d") : d.ToString(); + return (_type == MySqlDbType.Date) ? d.ToString("d", CultureInfo.InvariantCulture) : d.ToString(CultureInfo.InvariantCulture); } string dateString = FormatDateCustom( diff --git a/MySQL.Data/src/Types/MySqlInt16.cs b/MySQL.Data/src/Types/MySqlInt16.cs index 6c8f5a64..e9a76518 100644 --- a/MySQL.Data/src/Types/MySqlInt16.cs +++ b/MySQL.Data/src/Types/MySqlInt16.cs @@ -66,7 +66,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.WriteInteger((long)v, 2); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlInt32.cs b/MySQL.Data/src/Types/MySqlInt32.cs index c3d53cd5..bef3bb1c 100644 --- a/MySQL.Data/src/Types/MySqlInt32.cs +++ b/MySQL.Data/src/Types/MySqlInt32.cs @@ -75,9 +75,9 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len { int v = val as int? ?? Convert.ToInt32(val); if (binary) - packet.WriteInteger((long)v, _is24Bit ? 3 : 4); + packet.WriteInteger(v, _is24Bit ? 3 : 4); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlInt64.cs b/MySQL.Data/src/Types/MySqlInt64.cs index 114f7a8d..794aff07 100644 --- a/MySQL.Data/src/Types/MySqlInt64.cs +++ b/MySQL.Data/src/Types/MySqlInt64.cs @@ -69,7 +69,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.WriteInteger(v, 8); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlSingle.cs b/MySQL.Data/src/Types/MySqlSingle.cs index 25a0747b..cf79a811 100644 --- a/MySQL.Data/src/Types/MySqlSingle.cs +++ b/MySQL.Data/src/Types/MySqlSingle.cs @@ -69,8 +69,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.Write(BitConverter.GetBytes(v)); else - packet.WriteStringNoNull(v.ToString("R", - CultureInfo.InvariantCulture)); + packet.WriteStringNoNull(v.ToString("R", CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlUByte.cs b/MySQL.Data/src/Types/MySqlUByte.cs index 63d75098..b4320ac8 100644 --- a/MySQL.Data/src/Types/MySqlUByte.cs +++ b/MySQL.Data/src/Types/MySqlUByte.cs @@ -66,7 +66,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.WriteByte(v); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlUInt16.cs b/MySQL.Data/src/Types/MySqlUInt16.cs index 8926a00a..494282d1 100644 --- a/MySQL.Data/src/Types/MySqlUInt16.cs +++ b/MySQL.Data/src/Types/MySqlUInt16.cs @@ -64,9 +64,9 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len { int v = (val is UInt16) ? (UInt16)val : Convert.ToUInt16(val); if (binary) - packet.WriteInteger((long)v, 2); + packet.WriteInteger(v, 2); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlUInt32.cs b/MySQL.Data/src/Types/MySqlUInt32.cs index d271b71b..68bec71e 100644 --- a/MySQL.Data/src/Types/MySqlUInt32.cs +++ b/MySQL.Data/src/Types/MySqlUInt32.cs @@ -79,7 +79,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object v, int lengt if (binary) packet.WriteInteger((long)val, _is24Bit ? 3 : 4); else - packet.WriteStringNoNull(val.ToString()); + packet.WriteStringNoNull(val.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal) diff --git a/MySQL.Data/src/Types/MySqlUInt64.cs b/MySQL.Data/src/Types/MySqlUInt64.cs index 55e0a542..bdeeaebc 100644 --- a/MySQL.Data/src/Types/MySqlUInt64.cs +++ b/MySQL.Data/src/Types/MySqlUInt64.cs @@ -69,7 +69,7 @@ void IMySqlValue.WriteValue(MySqlPacket packet, bool binary, object val, int len if (binary) packet.WriteInteger((long)v, 8); else - packet.WriteStringNoNull(v.ToString()); + packet.WriteStringNoNull(v.ToString(CultureInfo.InvariantCulture)); } IMySqlValue IMySqlValue.ReadValue(MySqlPacket packet, long length, bool nullVal)