CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
368 stars 291 forks source link

Dollar sign in patterns is not working anymore #384

Closed zidekmat closed 6 years ago

zidekmat commented 6 years ago

Hi, in current version 0.13.82 (tried also devel 0.13.38) I'm having trouble specifying valid pattern to match whole string. Let's suppose this module:

module "test-module" {
  namespace "urn:ns:yang:test-module";
  prefix "test-module";

  container "nemea-supervisor" {
    leaf "name" {
      type "string" { pattern "^XXX$"; }
      default "XXX";
    }
  }
}

If I run yanglint -VVV test-module.yang, I get following:

Validating test-module.yang schema file.
verb: Resolving type default "�cX" failed, it will be attempted later.
verb: Resolving "test-module" unresolved schema nodes and their constraints...
err : Value "XXX" does not satisfy the constraint "^XXX$" (range, length, or pattern). (/test-module:fake-default)
err : Module "test-module" parsing failed.

I also tried patterns like "^XXX\$", "^XXX\\$", '^XXX$', '^XXX\$', '^XXX\\$' but none seem to work. Do I specify the end of string in a bad way or is a bug?

rkrejci commented 6 years ago

Hi, the regular expression language used by YANG implicitly anchors all regular expressions at the head and tail, see https://www.w3.org/TR/2004/REC-xmlschema-2-20041028/#regexs. So the correct pattern is just "XXX".

zidekmat commented 6 years ago

Great, thanks for explanation :)