cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
797
Views
0
Helpful
2
Replies

warning: illegal character after \

macauley
Level 1
Level 1

This has to do with ncsc compile errors characters in “pattern” statements in the YANG modules.  I am encountering this issue under NSO 5.7.1.1.  Here is an example error message:

Warning: yang/coriant-common@2021-01-20.yang:237:29: warning: illegal character after \

This is related to the pattern statement `pattern "[A-Za-z0-9_\-/,\.]*";` which passes YANG regex and W3G validation in the following tool https://yangcatalog.org/yangre.

 
 
  grouping "user-defined-alias" {
    leaf "alias-name" {
      type "string" {
        length "0..256";
        pattern "[A-Za-z0-9_\-/,\.]*";
      }
 
      description
        "User defined alias for this entity. Must be an alphanumeric string with dash or underscore";
    }
  }
 
It looks like the escaped character “\-“ is not liked by the ncsc complier.  Here is a list of all the patterns that failed compiling of the YANG.  These all pass regex validation but are generating ncsc compiler errors.
 
pattern "(((80|[1-7][0-9]|[1-9])(\.\.(80|[1-7][0-9]|[1-9]))?)(,((80|[1-7][0-9]|[1-9])(\.\.(80|[1-7][0-9]|[1-9]))?))*)?”;
pattern "((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.)*([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.?)|\.";
pattern "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])));
pattern "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\p{N}\p{L}]+)?";
pattern "(([0-1](\.[1-3]?[0-9]))|(2\.(0|([1-9]\d*))))(\.(0|([1-9]\d*)))*";
pattern "(([0-9]+(\.\.[0-9]+)?)(,([0-9]+(\.\.[0-9]+)?))*)?";
pattern "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])
pattern "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
pattern "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N}\p{L}]+)?";
pattern "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]):(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9])";
pattern "(([A-Za-z0-9_\-][A-Za-z0-9_\-\+]*)|(\+loc:([A-Za-z0-9]{1,})\+rmt:([A-Za-z0-9]{1,})))?";
pattern "(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(
pattern "(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?";
pattern "((ftp|sftp|ftps|scp|http):
pattern "(\d{2}
pattern "(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-]\d{2}:\d{2}))?";
pattern "(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-]\d{2}:\d{2}))|(all)";
pattern ".|..|[^xX].*|.[^mM].*|..[^lL].*";
pattern "[!-~\s]*";
pattern "[0-9\.]*";
pattern "[0-9a-fA-F:\.]*";
pattern "[A-Za-z0-9][a-zA-Z0-9\-_
pattern "[A-Za-z0-9][a-zA-Z0-9\-_:\.
pattern "[A-Za-z0-9][a-zA-Z0-9\-_:\.]*";
pattern "[A-Za-z0-9_\-
pattern "[A-Za-z0-9_\-\.]*";
pattern "[^\*].*";
pattern "[a-zA-Z_][a-zA-Z0-9\-_.]*";
pattern "[a-z_.][a-z0-9_\-.]*[$]?";
pattern "\*";
pattern "\d*(\.\d*){1,127}";
pattern "\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-]\d{2}:\d{2})";
pattern "route\-origin:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]):(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9])";
pattern "route\-origin:(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9]):(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[1-9])";
pattern "route\-target:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]):(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9])";
pattern "route\-target:(6[0-5][0-5][0-3][0-5]|[1-5][0-9]{4}|[1-9][0-9]{1,4}|[0-9]):(4[0-2][0-9][0-4][0-9][0-6][0-7][0-2][0-9][0-6]|[1-3][0-9]{9}|[1-9]([0-9]{1,7})?[0-9]|[1-9])";

Can anyone explain why these pass YANG regex validation but fail ncsc compile?

Thank you.

 

2 Replies 2

cealves
Cisco Employee
Cisco Employee

TLDR: You should use single quoted strings if you want to use escaping characters.

ex:

 

leaf alias-name {
    type string {
        length '0..256';
        pattern '[A-Za-z0-9_\-/,\.]*';
    }
}

 

 

Explanation:

On RFC6020 under the quoting section you can read:

  A single-quoted string (enclosed within ' ') preserves each character
   within the quotes.  A single quote character cannot occur in a
   single-quoted string, even when preceded by a backslash.

   Within a double-quoted string (enclosed within " "), a backslash
   character introduces a special character, which depends on the
   character that immediately follows the backslash:

    \n      new line
    \t      a tab character
    \"      a double quote
    \\      a single backslash

So since you're using double quotes and adding a backslash, yang thinks that you're introducing a special character, but you're not, your backslash is actually an escaping character for the regex.

So, to avoid this kind of issues I would recommend you to use single quoted strings on your patterns, such as the ietf draft rfc6087bis recommends:

A single quoted string SHOULD be used to specify the
   pattern, since a double-quoted string can modify the content.

 Hope it's clear.

César Alves

Thank you.  That fixed my issue.