Uploaded image for project: 'mdsal'
  1. mdsal
  2. MDSAL-661

Generated enforcers fail to intepret length restriction

XMLWordPrintable

      Currently this YANG:

       

        typedef foo { 
          type string { 
            length 1; 
          } 
        } 

       

      translates to this enforcement code:

       

          private static void check_valueLength(final String value) { 
              final int length = value.length(); 
              if (length == 1) { 
                  return; 
              } 
              CodeHelpers.throwInvalidLength("[[1..1]]", value); 
          } 

      which looks good on surface, but has a slight flaw. RFC7950 specifies that:

       

       

      A "length" statement restricts the number of Unicode characters in
      the string.

      What we are checking is the number of code units, not code points. The difference becomes obvious when characters outside the Basic Multilingual Plane are encountered:

       

      // U+1F31E
      final String str = "�"
      // Encodes as "\u0xD83C\u0xDF1E", i.e. two code units
      assertEquals(2, str.length());
      // The two code units together yield a single code point
      assertEquals(1, str.codePointCount(0, str.length());
      

       

       

       

            rovarga Robert Varga
            rovarga Robert Varga
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: