2

I was trying to accept multiple values including empty in Mountebank predicates.

As per below in the query parameter I want to accept both false and empty value.

Tried below and it doesn't accept neither isValid=false nor isValid=

"predicates":[
   {
      "matches":{
         "method":"GET",
         "path":"/accounts",
         "query":{
            "isValid":"/false|^null$/"
         }
      }
   }
],
"responses":[
   {
      "....."
   }
]

I tried below option as well as per this

"isValid":"/false.^null$|^null$.false/"
Shabar
  • 2,617
  • 11
  • 57
  • 98

1 Answers1

1

You need to use

"matches": {
    "data": "^(?:false)?$" 
}

Here,

  • ^ - matches start of string
  • (?:false)? - an optional (due to ? at the end) non-capturing group that matches a char sequence false one or zero times
  • $ - end of string.
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • As per the question I believe it should be `false` NOT `first`. Further mine worked without `colon` and leading `?` i.e. `^(false)?$` – Shabar Oct 07 '20 at 11:01
  • 1
    @SMPH If it is JavaScript, you can rely on the non-capturing group, too. Capturing groups keep the captured value in the match object, which is a redundant overhead. – Wiktor Stribiżew Oct 07 '20 at 11:11