jhoek / UncommonSense.CBreeze

C#/PowerShell API for the Dynamics NAV C/AL object text format
MIT License
6 stars 4 forks source link

Error when parsing a test object #126

Closed FSharpCSharp closed 6 years ago

FSharpCSharp commented 6 years ago

I have now played a little with the library, and tried some test cases. This also includes the recognition of objects that contain special characters and brackets in the name and in various variables.

But I had some problems testing the following file. This file is a valid object file that you can read into Dynamics NAV exactly as it is. The file looks funny, but it works. I didn't make these up. It is only used by our development system to test various special character tests on SQL Server and during compilation.

Therefore, the file should also be readable, even if these cases may hardly occur in reality, but they can occur.

TestTable.txt

jhoek commented 6 years ago

Haha! That probably breaks my parser (entirely based on reverse engineering) in a million different ways! As such, a very useful test! I'll look into this ASAP.

jhoek commented 6 years ago

@FSharpCSharp Getting (object) dates and times to match without knowing the culture used to export them cannot be done with 100% accuracy. For now, when testing with your sample file, I'll reformat the date/time to match my local settings. Makes sense?

jhoek commented 6 years ago

@FSharpCSharp Do you know if it's only curly brackets that cause the square brackets around property values containing them? Or are there other characters that trigger this behaviour?

FSharpCSharp commented 6 years ago

@jhoek So what I know about all the bracketed stories so far is this:

There are apparently escape sequences to allow the parentheses and special characters. However, the square brackets are always the object if it is a sign that has an ambiguous meaning. For field names, for example, it is also the semicolon. This makes sense because it can also serve as a separator between the individual values.

There is a similar behavior with multi-language texts, if the text contains an is-identical character, or quotation marks. But beware! What I know so far is that this kind of escaping can occur almost everywhere. This means that it would be best to provide for this case everywhere. But you can play through such a case relatively well in NAV by building a page around this table or using it elsewhere. A similar behaviour must take place here.

Supplement. If the text now also contains such brackets, then these must be specified twice to be recognized as real characters. This means, for example, that the following text would become the following text:

Original: This is a Test []

Text-File: [This is a Test []]]

FSharpCSharp commented 6 years ago

@jhoek I built you some more examples of the special characters today. I attached this file to you.

special_char_tests.txt

FSharpCSharp commented 6 years ago

@jhoek I found something else for you to see the date and time. The detection is indeed dependent on many parameters. But I would try the TryParse function of DateTime if I were you. There is also an overload for this method that uses the IFormatProvider interface. Perhaps it would be an option to try to determine these options using these parameters, and additionally offer the user the possibility to provide an IFormatProvider. It goes even further: This sometimes affects not only the date formats but also the entire character set of the object. So far you are using the function "Encoding.GetEncoding(850)". This will work for most Western European countries, but not for all languages. Here it would be good if you could record this information from the user and get all the information at runtime using the IFormatProvider.