DevToys-app / DevToys

A Swiss Army knife for developers.
https://devtoys.app/
MIT License
27.35k stars 1.47k forks source link

adds an extra space #677

Closed shabelski89 closed 7 months ago

shabelski89 commented 2 years ago

Description

Hello everyone! DevToys add an extra space in field name, when formatting SQL query wuth special symbol. To Reproduce:

  1. go to Formatter, SQL
  2. paste query below SELECT ACCOUNT, SUM(C.AMOUNT_$ - C.VAT_$) AS bills FROM TABLE_CHARGE GROUP BY ACCOUNT;
  3. see result in output window SELECT ACCOUNT, SUM(C.AMOUNT_ $ - C.VAT_ $) AS bills FROM TABLE_CHARGE GROUP BY ACCOUNT; see a picture for proof devtoy_bug

Steps To Reproduce

No response

Expected behavior

Expected behavior - don't split field name.

DevToys Version

Версия 1.0.10.0 | X64 | RELEASE | b949a18 | b949a18

Relevant Assets/Logs

- [09/28/2022 13:14:01]

Feature name: SmartDetection - Check if tool is recommended Custom message: Tool : Xml Validator Exception message: Data at the root level is invalid. Line 1, position 2. Exception stack trace: at System.Xml.XmlTextReaderImpl.Throw(Exception) + 0x6c at System.Xml.XmlTextReaderImpl.Throw(String, String) + 0x56 at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() + 0x1a5 at System.Xml.XmlTextReaderImpl.ParseDocumentContent() + 0x22d at System.Xml.XmlTextReaderImpl.Read() + 0x355 at System.Xml.XmlTextReader.Read() + 0xf at System.Xml.Schema.Parser.StartParsing(XmlReader, String) + 0xb7 at System.Xml.Schema.Parser.Parse(XmlReader, String) + 0x10 at System.Xml.Schema.XmlSchema.Read(XmlReader, ValidationEventHandler) + 0x86 at DevToys.ViewModels.Tools.XmlValidator.XmlValidatorToolProvider.ValidateXsdData(String) + 0x122 at DevToys.ViewModels.Tools.XmlValidator.XmlValidatorToolProvider.CanBeTreatedByTool(String) + 0x18 at DevToys.Api.Tools.ToolProviderViewItem.d40.MoveNext() + 0xc0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() + 0x21 at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task) + 0x70 at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task) + 0x38 at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task) + 0x17 at System.Runtime.CompilerServices.TaskAwaiter.GetResult() + 0xb at DevToys.ViewModels.MainPageViewModel.<>cDisplayClass88_1.<b__2>d.MoveNext() + 0x107

nickdevore commented 2 years ago

I'm seeing this, but when I'm using a parameter.

declare @myParameterName DateTime2 = GetUTCDate();

formats to

DECLARE @ myParameterName DATETIME2 = GETUTCDATE();

I think the tokenizer is missing a check for parameter identifiers (@)? And, I believe the bug noted here is happening because of line 73 in Tokenizer

 _indentNamedPlaceholderRegex = RegexFactory.CreatePlaceholderRegex(namedPlaceholderTypes, "[a-zA-Z0-9._$]+");

...but I can't quite figure out if the parameter tokenizer is totally missing (I think it is) or if I just need to add a couple of lines of code to an existing function to help it find the @ for parameters. Help me know which way to go and I'll submit a PR for the parameters. And, if you tell me if I found the right place, I'll fix this original bug too