From 659c41af6fddcbec557f77fb43601ee2c95eb32d Mon Sep 17 00:00:00 2001 From: mbdavid Date: Wed, 24 Aug 2016 20:19:40 -0300 Subject: [PATCH] Bugfix #284 revert connstring string regex --- LiteDB.Core.nuspec | 2 +- .../Properties/AssemblyInfo.cs | 4 +- .../Properties/AssemblyInfo.cs | 4 +- LiteDB.Shell/Properties/AssemblyInfo.cs | 4 +- LiteDB.Tests/Properties/AssemblyInfo.cs | 4 +- LiteDB.nuspec | 2 +- LiteDB/Properties/AssemblyInfo.cs | 4 +- LiteDB/Utils/ConnectionString.cs | 66 ++++--------------- 8 files changed, 26 insertions(+), 64 deletions(-) diff --git a/LiteDB.Core.nuspec b/LiteDB.Core.nuspec index 1ad5a12ed..2e6c6a344 100644 --- a/LiteDB.Core.nuspec +++ b/LiteDB.Core.nuspec @@ -2,7 +2,7 @@ LiteDB.Core - 2.0.1 + 2.0.2 LiteDB Portable Mauricio David http://www.litedb.org diff --git a/LiteDB.Platform/LiteDB.Tests.Android/Properties/AssemblyInfo.cs b/LiteDB.Platform/LiteDB.Tests.Android/Properties/AssemblyInfo.cs index 9843532a4..8ab21b202 100644 --- a/LiteDB.Platform/LiteDB.Tests.Android/Properties/AssemblyInfo.cs +++ b/LiteDB.Platform/LiteDB.Tests.Android/Properties/AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: NeutralResourcesLanguage("en")] -[assembly: AssemblyVersion("2.0.1.0")] -[assembly: AssemblyFileVersion("2.0.1.0")] +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] diff --git a/LiteDB.Platform/LiteDB.Tests.DotNet45/Properties/AssemblyInfo.cs b/LiteDB.Platform/LiteDB.Tests.DotNet45/Properties/AssemblyInfo.cs index 3a7ebc865..61fed081c 100644 --- a/LiteDB.Platform/LiteDB.Tests.DotNet45/Properties/AssemblyInfo.cs +++ b/LiteDB.Platform/LiteDB.Tests.DotNet45/Properties/AssemblyInfo.cs @@ -12,5 +12,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("dbe3535c-60f3-4e17-9a05-abe280d35b74")] -[assembly: AssemblyVersion("2.0.1.0")] -[assembly: AssemblyFileVersion("2.0.1.0")] +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] diff --git a/LiteDB.Shell/Properties/AssemblyInfo.cs b/LiteDB.Shell/Properties/AssemblyInfo.cs index 3e5d9692b..df565c96c 100644 --- a/LiteDB.Shell/Properties/AssemblyInfo.cs +++ b/LiteDB.Shell/Properties/AssemblyInfo.cs @@ -12,7 +12,7 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("01ce385b-31a7-4b1a-9487-23fe8acb3888")] -[assembly: AssemblyVersion("2.0.1.0")] -[assembly: AssemblyFileVersion("2.0.1.0")] +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/LiteDB.Tests/Properties/AssemblyInfo.cs b/LiteDB.Tests/Properties/AssemblyInfo.cs index d99a855e6..ddc176545 100644 --- a/LiteDB.Tests/Properties/AssemblyInfo.cs +++ b/LiteDB.Tests/Properties/AssemblyInfo.cs @@ -13,5 +13,5 @@ [assembly: NeutralResourcesLanguage("en")] [assembly: ComVisible(false)] [assembly: Guid("de183e83-7df6-475c-8185-b0070d098821")] -[assembly: AssemblyVersion("2.0.1.0")] -[assembly: AssemblyFileVersion("2.0.1.0")] \ No newline at end of file +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] \ No newline at end of file diff --git a/LiteDB.nuspec b/LiteDB.nuspec index 71165d5f1..80330201d 100644 --- a/LiteDB.nuspec +++ b/LiteDB.nuspec @@ -2,7 +2,7 @@ LiteDB - 2.0.1 + 2.0.2 LiteDB Mauricio David http://www.litedb.org diff --git a/LiteDB/Properties/AssemblyInfo.cs b/LiteDB/Properties/AssemblyInfo.cs index 5ef697948..f6d7e960b 100644 --- a/LiteDB/Properties/AssemblyInfo.cs +++ b/LiteDB/Properties/AssemblyInfo.cs @@ -12,6 +12,6 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("54989b5c-4bcf-4d58-b8ba-9b014a324f76")] -[assembly: AssemblyVersion("2.0.1.0")] -[assembly: AssemblyFileVersion("2.0.1.0")] +[assembly: AssemblyVersion("2.0.2.0")] +[assembly: AssemblyFileVersion("2.0.2.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/LiteDB/Utils/ConnectionString.cs b/LiteDB/Utils/ConnectionString.cs index bf07fda3d..142a18184 100644 --- a/LiteDB/Utils/ConnectionString.cs +++ b/LiteDB/Utils/ConnectionString.cs @@ -13,65 +13,27 @@ public class ConnectionString { private Dictionary _values; - private static readonly Regex keyValuePairRegex = new Regex( - @"^( - ;* - (? - ((?[a-zA-Z][a-zA-Z0-9-_]*)=)? - (? - (? - (?['""]) - ((\\\k)|((?!\k).))* - \k? - ) - |(?[^\s]+) - ) - ) - ;* - )*$", - RegexOptions.Singleline | RegexOptions.IgnorePatternWhitespace | - RegexOptions.ExplicitCapture - ); - public ConnectionString(string connectionString) { if (string.IsNullOrEmpty(connectionString)) throw new ArgumentNullException("connectionString"); - _values = new Dictionary(StringComparer.OrdinalIgnoreCase); - Match match = keyValuePairRegex.Match(connectionString); - foreach (Capture pair in match.Groups["pair"].Captures) + // Create a dictionary from string name=value collection + if (connectionString.Contains("=")) { - var key = - match.Groups["key"].Captures.Cast() - .FirstOrDefault( - keyMatch => - keyMatch.Index >= pair.Index && keyMatch.Index <= pair.Index + pair.Length); - var value = - match.Groups["value"].Captures.Cast() - .FirstOrDefault( - valueMatch => - valueMatch.Index >= pair.Index && valueMatch.Index <= pair.Index + pair.Length); - if (key == null && value != null) - { - _values.Add(value.Value.Trim().Trim('"'), null); - } - if (key != null) - { - _values.Add(key.Value.Trim().Trim('"'), value?.Value.Trim().Trim('"')); - } + _values = connectionString.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries) + .Select(t => t.Split(new char[] { '=' }, 2)) + .ToDictionary(t => t[0].Trim().ToLower(), t => t.Length == 1 ? "" : t[1].Trim(), StringComparer.OrdinalIgnoreCase); } - - // return if there is more than one pair - // or the only pair's name is 'filename' - // or the only pair's value is not null - if (_values.Count > 1 || _values.ContainsKey("filename") || !_values.ContainsValue(null)) - return; - - _values["filename"] = (_values.Count > 0 ? _values.Keys.FirstOrDefault() : connectionString.Trim().Trim('"')) ?? - string.Empty; -#if !PCL - _values["filename"] = Path.GetFullPath(_values["filename"]); + else + { + // If connectionstring is only a filename, set filename + _values = new Dictionary(StringComparer.OrdinalIgnoreCase); +#if PCL + _values["filename"] = connectionString; +#else + _values["filename"] = Path.GetFullPath(connectionString); #endif + } } public T GetValue(string key, T defaultValue)