flaviostutz / ruller-dsl-feature-flag

A feature flag engine that can be used to enable, change or rollout features of a system dynamically based on system or user attributes
MIT License
2 stars 6 forks source link

The equality operator is not working for numbers #5

Closed MichaelRSilva closed 4 years ago

MichaelRSilva commented 4 years ago

The ruller-dsl-feature-flag doesn't behave as expected when there is a rule that compares numbers with the equality operator: input:age == 79.

Examples:

This works well

[
  {
    "label": "menu1",
    "_condition": "input:weight == '79'",
    "_items": [
      {
        "label": "menu1.1",
        "uri": "/menu1.1"
      }
    ]
  },
  {
    "label": "menu2",
    "_condition": "input:weight < 79",
    "_items": [
      {
        "label": "menu2.1",
        "uri": "/menu2.1"
      }
    ]
  },
  {
    "label": "menu3",
    "_condition": "input:weight > 79",
    "_items": [
      {
        "label": "menu3.1",
        "uri": "/menu3.1"
      }
    ]
  }
]

This doesn't work well

[
  {
    "label": "menu1",
    "_condition": "input:weight == 79",
    "_items": [
      {
        "label": "menu1.1",
        "uri": "/menu1.1"
      }
    ]
  }
]

The code needs to be adjusted for the equality between numbers to work as expected.

MichaelRSilva commented 4 years ago

The code on line 367 of the main.go file regexp.MustCompile("input:([a-z0-9-_]+)\\s*[><==]\\s*[0-9]+") was not understanding the symbol "==" as a single symbol, as it was enclosed in square brackets.

Just change or adjust the regex regexp.MustCompile("input:([a-z0-9-_]+)\\s*([><]|==|!=)\\s*[0-9]+") for both equality == and inequality != to work as expected.