1 Reply Latest reply on Mar 25, 2016 7:29 AM by TSGal

    Inconsistent treatment of Null characters

    jbante

      Product and version FileMaker Pro Advanced 14.0.5

      OS and version Mac OS X 10.11.3

       

      Description


      I'm pointing to two problems:

       

      1. The Char function cannot produce the null character. The documentation for the function notes this. Without knowing the internals of FileMaker's text handling, it might be reasonable to presume that FileMaker has some difficulty handling this character in general. However, the null character can be generated with Base64Decode ( "AA==" ), and the null character can be stored in fields. So there must not be anything architecturally important about the null character receiving special treatment. Char ( 0 ) returning an empty string is inconsistent with the behavior of the Char function for other values and with the rest of FileMaker, apparently for no good reason.

       

      2. The Base64Encode function does not properly encode text containing the null character. Any text before the null character is encoded, but the null character and any text after are not encoded. This is inconsistent with the Base64Encode function's handling of container data containing null bytes, and deviates from the expected behavior of Base64Encode as a proper inverse of Base64Decode, which can output null characters in text without a problem.

       

      The latter is more irritating than the former for me personally. The Base64Decode function is essential for generating arbitrary binary files using only built-in FileMaker features. It turns out that the Base64Encode function can be a much faster method for encoding data to base 64 than other techniques. However, this doesn't work for data that can include, or in some configurations requires, null bytes, e.g. PNG.

       

      How to replicate


      IsEmpty ( Char ( 0 ) ) = 1 // should be 0

      Length ( Char ( 0 ) ) = 0 // should be 1

      Code ( Char ( 0 ) ) = <empty string> // should be 0

       

      IsEmpty ( Base64Decode ( "AA==" ) ) = False // good

      Length ( Base64Decode ( "AA==" ) ) = 1 // good

      Code ( Base64Decode ( "AA==" ) ) = 0 // good

       

      Let ( [

      _source = "123" & Base64Decode ( "AA==" ) & "123"

      ] ;

      _source ≠ Base64Decode ( Base64Encode ( _source ) ) // should be equal

      )