durable_rules 2.0.22 → 2.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ea83e9efc9d1e06b799a9408e24dc95126cadcdc
4
- data.tar.gz: 9334d4fb5bbe5c97d8e46cf00a624adcd782af86
3
+ metadata.gz: 5220161e2cc19405339ce104109a5ab075b092d5
4
+ data.tar.gz: 5e377d29c7c5d3985ddd8649b5abbf264f7d6612
5
5
  SHA512:
6
- metadata.gz: 9240234e76cf597c487320d53ec9ebe9ba9a7ba65a0f64a685de3eb2b037457a11eb89fd61eca7dc4135aa473ae86dc92aebea8eb941d504270c4de29416e974
7
- data.tar.gz: 1056a380df74c2a30b266d33a09c6745bcd41b1b255e2f6a9628fb5c5d30db65c83606b45e7758d679f36a50026a9ea1ba98c94a308f51a323ace387ee3fd68e
6
+ metadata.gz: 0f86aca1a3edb8a690940bbbccd9802399174bc23c15bae438b95bde71bb9322374ee58caca508f1dc47dbfc25d5ea128d4479541b34645d16c4b20d577f9119
7
+ data.tar.gz: 9304dd821caa413367edffa5e410bbf19f7a504ab06182796d7cdd2d8e1ad27454382968b64483a32757e968b50f20dbd616dd5028a6e7b4c2cd54f6e3f5d13c
@@ -9,9 +9,12 @@ module Durable
9
9
  @@main_host = Engine::Host.new
10
10
  end
11
11
 
12
- @@main_host.register_rulesets @@rulesets
13
-
14
- @@rulesets = {}
12
+ begin
13
+ @@main_host.register_rulesets @@rulesets
14
+ ensure
15
+ @@rulesets = {}
16
+ end
17
+
15
18
  @@main_host
16
19
  end
17
20
 
@@ -486,13 +486,67 @@ static unsigned int reduceExpression(ruleset *tree,
486
486
 
487
487
  if (currentExpression->right.type == JSON_REGEX || currentExpression->right.type == JSON_IREGEX) {
488
488
  targetProperty->type = JSON_BOOL;
489
+ targetProperty->value.b = 0;
490
+
491
+ char *leftString = "";
492
+ unsigned short leftLength = 0;
493
+ switch(leftProperty->type) {
494
+ case JSON_INT:
495
+ {
496
+ #ifdef _WIN32
497
+ leftString = (char *)_alloca(sizeof(char)*(MAX_INT_LENGTH + 1));
498
+ sprintf_s(leftString, sizeof(char)*(MAX_INT_LENGTH + 1), "%lld", leftProperty->value.i);
499
+ #else
500
+ char newString[MAX_INT_LENGTH + 1];
501
+ leftString = newString;
502
+ snprintf(leftString, sizeof(char)*(MAX_INT_LENGTH + 1), "%lld", leftProperty->value.i);
503
+ #endif
504
+ leftLength = strlen(leftString);
505
+ break;
506
+ }
507
+ case JSON_DOUBLE:
508
+ {
509
+ #ifdef _WIN32
510
+ leftString = (char *)_alloca(sizeof(char)*(MAX_DOUBLE_LENGTH + 1));
511
+ sprintf_s(leftString, sizeof(char)*(MAX_DOUBLE_LENGTH + 1), "%f", leftProperty->value.d);
512
+ #else
513
+ char newString[MAX_DOUBLE_LENGTH + 1];
514
+ leftString = newString;
515
+ snprintf(leftString, sizeof(char)*(MAX_DOUBLE_LENGTH + 1), "%f", leftProperty->value.d);
516
+ #endif
517
+ leftLength = strlen(leftString);
518
+ break;
519
+ }
520
+ case JSON_BOOL:
521
+ if (leftProperty->value.b) {
522
+ leftString = "true";
523
+ leftLength = 4;
524
+ }
525
+ else {
526
+ leftString = "false";
527
+ leftLength = 5;
528
+ }
529
+
530
+ break;
531
+ case JSON_NIL:
532
+ leftString = "nil";
533
+ leftLength = 3;
534
+ break;
535
+ case JSON_STRING:
536
+ leftString = leftProperty->value.s;
537
+ leftLength = leftProperty->valueLength;
538
+ break;
539
+ }
540
+
489
541
  targetProperty->value.b = evaluateRegex(tree,
490
- leftProperty->value.s,
491
- leftProperty->valueLength,
542
+ leftString,
543
+ leftLength,
492
544
  (currentExpression->right.type == JSON_REGEX) ? 0 : 1,
493
545
  currentExpression->right.value.regex.vocabularyLength,
494
546
  currentExpression->right.value.regex.statesLength,
495
547
  currentExpression->right.value.regex.stateMachineOffset);
548
+
549
+
496
550
  return RULES_OK;
497
551
  }
498
552
 
@@ -23,6 +23,7 @@
23
23
  #define MAX_SET 8192
24
24
  #define MAX_LIST 1024
25
25
  #define MAX_INTERVAL 100
26
+ #define MAX_REFCOUNT 1000
26
27
 
27
28
 
28
29
  #define CREATE_QUEUE(type) \
@@ -597,10 +598,6 @@ static unsigned int linkStates(state *previousState,
597
598
  previousState->transitions[previousState->transitionsLength].next = nextState;
598
599
  ++previousState->transitionsLength;
599
600
  ++nextState->refCount;
600
- if (previousState->transitionsLength == MAX_TRANSITIONS) {
601
- return ERR_REGEX_MAX_TRANSITIONS;
602
- }
603
-
604
601
  return RULES_OK;
605
602
  }
606
603
 
@@ -852,10 +849,18 @@ static unsigned int validateGraph(char **first, char *last) {
852
849
  switch (currentToken.type) {
853
850
  case REGEX_SYMBOL:
854
851
  case REGEX_UNION:
855
- case REGEX_STAR:
856
852
  case REGEX_PLUS:
857
- case REGEX_QUESTION:
858
853
  break;
854
+ case REGEX_STAR:
855
+ case REGEX_QUESTION:
856
+ {
857
+ char *nextFirst = *first;
858
+ token nextToken;
859
+ unsigned int nextResult = readNextToken(&nextFirst, last, &nextToken);
860
+ if (nextResult == REGEX_PARSE_OK && nextToken.type == REGEX_STAR) {
861
+ return ERR_REGEX_INVALID;
862
+ }
863
+ }
859
864
  case REGEX_REGEX:
860
865
  result = validateGraph(first, last);
861
866
  if (result != REGEX_PARSE_OK) {
@@ -1141,7 +1146,7 @@ static unsigned int transformToDFA(state *nfa,
1141
1146
  }
1142
1147
  }
1143
1148
 
1144
- DEQUEUE(&currentState);
1149
+ DEQUEUE(&currentState);
1145
1150
  }
1146
1151
 
1147
1152
  return RULES_OK;
@@ -1343,6 +1348,12 @@ unsigned int compileRegex(void *tree,
1343
1348
  if (result != RULES_OK) {
1344
1349
  return result;
1345
1350
  }
1351
+
1352
+ if (!*vocabularyLength || !*statesLength) {
1353
+ return ERR_REGEX_INVALID;
1354
+ }
1355
+
1356
+
1346
1357
  void *newStateMachine;
1347
1358
  result = storeRegexStateMachine((ruleset *)tree,
1348
1359
  *vocabularyLength,
@@ -1,6 +1,6 @@
1
1
  #include "state.h"
2
2
 
3
- // #define _PRINT 1
3
+ //#define _PRINT 1
4
4
 
5
5
  #define OP_NOP 0
6
6
  #define OP_LT 0x01
@@ -40,6 +40,7 @@
40
40
  #define ERR_REGEX_LIST_FULL 505
41
41
  #define ERR_REGEX_SET_FULL 506
42
42
  #define ERR_REGEX_CONFLICT 507
43
+ #define ERR_REGEX_INVALID 508
43
44
 
44
45
  #define NEXT_BUCKET_LENGTH 512
45
46
  #define NEXT_LIST_LENGTH 128
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: durable_rules
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.22
4
+ version: 2.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesus Ruiz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-23 00:00:00.000000000 Z
11
+ date: 2020-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake