soygul / NBug

Automated bug reporting library for .NET
http://soygul.com/nbug
MIT License
191 stars 78 forks source link

Bug in ConnectionStringParser. #64

Closed Anandir closed 8 years ago

Anandir commented 8 years ago

I've found a pretty funny bug inside the ConnectionStringParser and I'm not sure if there is a "elegant way" for solve it. If in the connection string you have an HTML entity you got a NBugConfigurationException.

For example: NBug.Settings.AddDestinationFromConnectionString("Type=Mail;CustomBody=My fancy body.;CustomSubject=Crash Report;" + "From=from@example.com;FromName=Bugreport - Me & my friends;" + "Password=mysecredpassword;Port=587;Priority=Low;SmtpServer=mailserver.example.com;To=me@example.com;" + "UseAttachment=True;UseAuthentication=True;UseSsl=False;Username=mymailusername;");

is a valid connection string, but it doesn't work because of the & in the FromName field. Maybe in the .conf file it work, but not if you put in the code directly and I'm not sure it's safe put the entities in the "normal" form (like & for the &).

Thanks a lot in advance!

soygul commented 8 years ago

Can you paste the full exception message? I'm on OS X so can't test it myself at the moment.

Anandir commented 8 years ago

My system is in italian, but I think I've done a quite correct translation (according to similar exceptions).

NBug.Core.Util.Exceptions.NBugConfigurationException was unhandled HResult=-2146233088 Message=Cannot parse the connection string supplied. The connection string may be malformed: Type=Mail;CustomBody=My fancy body.;CustomSubject=Crash Report;From=from@example.com;FromName=Bugreport - Me & my friends;Password=mysecredpassword;Port=587;Priority=Low;SmtpServer=mailserver.example.com;To=me@example.com;UseAttachment=True;UseAuthentication=True;UseSsl=False;Username=mymailusername; MisconfiguredProperty="" Source=NBug StackTrace: in NBug.Core.Util.ConnectionStringParser.Parse(String connectionString) in NBug.Settings.AddDestinationFromConnectionString(String connectionString) in .Program.Main(String[] args) in \Program.cs:line 64 in System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) in System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) in Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() in System.Threading.ThreadHelper.ThreadStart_Context(Object state) in System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) in System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) in System.Threading.ThreadHelper.ThreadStart() InnerException: HResult=-2147024809 Message=An item with the same key has already been added. Source=mscorlib StackTrace: in System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) in System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) in System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) in NBug.Core.Util.ConnectionStringParser.Parse(String connectionString) InnerException:

soygul commented 8 years ago

Ok it's a documentation issue rather than a parser issue. You can't have semicolon inside the connection strings except for separators. Replace & with &amp\; or just use the word and and try.

Meanwhile I'll improve the docs on this.

Anandir commented 8 years ago

Good :). It wasn't something "big", but a minor thing. Thanks a lot for your time/work!

soygul commented 8 years ago

:+1:

Stef569 commented 8 years ago

I think this issue can be closed? The exception message is clear: Cannot parse the connection string supplied. The connection string may be malformed.

Or should the program check for a ; character and show a specific message like The connection string {0} contains a ; character please remove this character from the connection string.

Anandir commented 8 years ago

For me yes.

Stef569 commented 8 years ago

Anandir you have that power! Please close this issue!

Anandir commented 8 years ago

Ups! Immediately !