nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: goldibex/targaryen
Pull request #97 (2016-12-09 03:00:03)

Fix snapshot parent
Should throw if node is the database root.


Patch:
diff --git a/lib/database.js b/lib/database.js
index 23ed713..98917c3 100644
--- a/lib/database.js
+++ b/lib/database.js
@@ -251,7 +251,7 @@ class RuleDataSnapshot {
    */
   parent() {
     if (!this[pathKey]) {
-      return null;
+      throw new Error('This node if the database root and has no parent.');
     }
 
     const path = this[pathKey].split('/').slice(0, -1).join('/');


Test patch:
diff --git a/test/spec/lib/database.js b/test/spec/lib/database.js
index ee11e2e..ba23896 100644
--- a/test/spec/lib/database.js
+++ b/test/spec/lib/database.js
@@ -133,7 +133,7 @@ describe('database', function() {
         expect(snap.parent().val()).to.deep.equal({foo});
       });
 
-      it.skip('fail if the snapshot was refering to the data root ', function() {
+      it('fail if the snapshot was refering to the data root ', function() {
         const data = null;
         const snap = database.create(rules, data).snapshot('/');
 
diff --git a/test/spec/lib/parser/fixtures.json b/test/spec/lib/parser/fixtures.json
index f35d121..55e4432 100644
--- a/test/spec/lib/parser/fixtures.json
+++ b/test/spec/lib/parser/fixtures.json
@@ -1056,6 +1056,12 @@
       "isValid": true,
       "failAtRuntime": false,
       "evaluateTo": true
+    },
+    {
+      "rule": "root.parent().exists()",
+      "user": "unauth",
+      "isValid": true,
+      "failAtRuntime": true
     }
   ]
 }
\ No newline at end of file
Repository: goldibex/targaryen
Pull request #103 (2016-12-15 16:56:20)

Fix deleting missing node
It was throwing when it couldn’t find the target parent.


Patch:
diff --git a/lib/database/store.js b/lib/database/store.js
index 57db948..d705b77 100644
--- a/lib/database/store.js
+++ b/lib/database/store.js
@@ -337,8 +337,7 @@ class DataNode {
     paths.split(path).every(key => {
       const siblings = Object.keys(currSrc).filter(k => k !== key);
 
-      // If the path doesn't exist from this point,
-      // or the only item is the one to remove,
+      // if the only item is the one to remove,
       // abort iteration.
       if (siblings.length === 0) {
         return false;
@@ -360,8 +359,8 @@ class DataNode {
         return currDest[key];
       };
 
-      return true;
-
+      // we can abort the iteration if the branch node to remove doesn't exist.
+      return currSrc !== undefined;
     });
 
     return DataNode.from(newRoot, this.$priority(), now || Date.now());


Test patch:
diff --git a/test/spec/lib/database/store.js b/test/spec/lib/database/store.js
index 0864029..168fe6a 100644
--- a/test/spec/lib/database/store.js
+++ b/test/spec/lib/database/store.js
@@ -258,6 +258,12 @@ describe('store', function() {
       expect(newRoot.$value()).to.eql({a: 1, b: {e: 3}});
     });
 
+    it('should remove non existant node', function() {
+      const newRoot = data.$remove('/x/y/z');
+
+      expect(newRoot.$value()).to.deep.equal(data.$value());
+    });
+
   });
 
   describe('#$child', function() {
Repository: goldibex/targaryen
Pull request #107 (2016-12-22 18:11:31)

Show when no read or write rules was found
Related to #105 


Patch:
diff --git a/lib/database/results.js b/lib/database/results.js
index 33ced55..fa9b5e4 100644
--- a/lib/database/results.js
+++ b/lib/database/results.js
@@ -34,11 +34,11 @@ class Result {
   }
 
   get logs() {
-    if (this[logsKey].length > 0) {
+    if (this[logsKey].some(r => r.kind === this.permissionType)) {
       return this[logsKey];
     }
 
-    return [{path: paths.trim(this.path), hasNoRules: true}];
+    return [{path: paths.trim(this.path), hasNoRules: true}].concat(this[logsKey]);
   }
 
   get allowed() {
@@ -52,14 +52,14 @@ class Result {
   get info() {
     const logs = this.logs.map(r => {
       if (r.hasNoRules === true) {
-        return `/${r.path}: <no rules>`;
+        return `/${r.path}: ${this.permissionType} <no rules>\n`;
       }
 
       const header = `/${r.path}: ${r.kind} "${r.rule}"`;
       const result = r.error == null ? r.value : r.error;
 
       if (r.detailed == null) {
-        return `${header}\n    => ${result}`;
+        return `${header}  => ${result}\n`;
       }
 
       return `${header}  => ${result}\n${pad.lines(r.detailed)}\n`;


Test patch:
diff --git a/test/spec/lib/database/index.js b/test/spec/lib/database/index.js
index cddb033..dc40459 100644
--- a/test/spec/lib/database/index.js
+++ b/test/spec/lib/database/index.js
@@ -1093,6 +1093,9 @@ describe('database', function() {
         rules: {
           foo: {
             '.write': true
+          },
+          bar: {
+            '.validate': true
           }
         }
       };
@@ -1105,7 +1108,9 @@ describe('database', function() {
 
       const result = db.update('/', patch);
 
-      expect(result.info).to.contain('/bar: <no rules>');
+      console.log(result.info);
+
+      expect(result.info).to.contain('/bar: write <no rules>');
 
     });
Repository: goldibex/targaryen
Pull request #116 (2017-01-24 13:50:29)

fix: allow literal computed property access (#115)
Firebase allows RuleDataSnapshot via computed property if the property is a literal node:

- `root["exists”]()` is allowed;
- `root["exi" + "sts”]()` is not allowed;
- `root[$foo]()` is not allowed.


Patch:
diff --git a/lib/parser/statement/base.js b/lib/parser/statement/base.js
index 272c64b..c8bdc20 100644
--- a/lib/parser/statement/base.js
+++ b/lib/parser/statement/base.js
@@ -50,6 +50,15 @@ class Node {
     this.inferredType = this.inferType(scope);
   }
 
+  /**
+   * AST node type.
+   *
+   * @return {string} This expression node type
+   */
+  get type() {
+    return this.astNode.type;
+  }
+
   /**
    * Hook called before type inferring.
    *
diff --git a/lib/parser/statement/member.js b/lib/parser/statement/member.js
index fe9ad88..1ff353f 100644
--- a/lib/parser/statement/member.js
+++ b/lib/parser/statement/member.js
@@ -83,10 +83,6 @@ class MemberNode extends Node {
 
     this.assertType(objectType, ['RuleDataSnapshot', 'string'], {msg});
 
-    if (objectType === 'RuleDataSnapshot' && this.computed) {
-      throw new ParseError(this, 'Invalid property access');
-    }
-
     if (types.isPrimitive(objectType)) {
       objectType = this.object.inferredType = 'string';
     }
@@ -111,7 +107,27 @@ class MemberNode extends Node {
   }
 
   inferType() {
-    return this.computed ? 'any' : this.property.inferredType;
+    if (!this.computed) {
+      return this.property.inferredType;
+    }
+
+    if (this.property.type !== 'Literal') {
+      return 'any';
+    }
+
+    const scope = MemberNode.properties[this.object.inferredType];
+
+    if (scope == null) {
+      return 'any';
+    }
+
+    const type = scope[this.property.value];
+
+    if (type == null) {
+      throw new ParseError(this, 'Invalid property access.');
+    }
+
+    return type;
   }
 
   inferAsStringMethod() {


Test patch:
diff --git a/test/spec/lib/parser/fixtures.json b/test/spec/lib/parser/fixtures.json
index 55e4432..ad081b3 100644
--- a/test/spec/lib/parser/fixtures.json
+++ b/test/spec/lib/parser/fixtures.json
@@ -1062,6 +1062,26 @@
       "user": "unauth",
       "isValid": true,
       "failAtRuntime": true
+    },
+    {
+      "rule": "root[\"exists\"]() == false",
+      "user": "unauth",
+      "isValid": true,
+      "failAtRuntime": false,
+      "evaluateTo": true
+    },
+    {
+      "rule": "root[\"exi\" + \"sts\"]() == false",
+      "user": "unauth",
+      "isValid": false
+    },
+    {
+      "rule": "root[$foo]() == false",
+      "user": "unauth",
+      "wildchildren": {
+        "$foo": "exists"
+      },
+      "isValid": false
     }
   ]
 }
\ No newline at end of file
Repository: goldibex/targaryen
Pull request #118 (2017-01-24 14:59:07)

fix: literal computed property access on string
Allow computed property access on fuzzy typed object when the property is literal matching a string method name.

Related to #115.


Patch:
diff --git a/lib/parser/statement/member.js b/lib/parser/statement/member.js
index 1ada939..95c6ca6 100644
--- a/lib/parser/statement/member.js
+++ b/lib/parser/statement/member.js
@@ -140,13 +140,11 @@ class MemberNode extends Node {
   inferAsStringMethod() {
     this.object.inferredType = 'string';
 
-    if (this.computed) {
-      return 'any';
+    if (!this.computed) {
+      this.property.inferredType = this.property.inferType(scopeFactory.create(MemberNode.properties.string));
     }
 
-    this.property.inferredType = this.property.inferType(scopeFactory.create(MemberNode.properties.string));
-
-    return this.property.inferredType;
+    return this.inferType();
   }
 
   evaluate(state) {


Test patch:
diff --git a/test/spec/lib/parser/fixtures.json b/test/spec/lib/parser/fixtures.json
index 10566ff..96b4a46 100644
--- a/test/spec/lib/parser/fixtures.json
+++ b/test/spec/lib/parser/fixtures.json
@@ -1087,6 +1087,18 @@
         "$foo": "exists"
       },
       "isValid": false
+    },
+    {
+      "rule": "auth.someString[\"contains\"](\"on\") == true",
+      "user": "bob",
+      "isValid": true,
+      "failAtRuntime": false,
+      "evaluateTo": true
+    },
+    {
+      "rule": "auth.someString[\"doesNotContains\"](\"on\") == false",
+      "user": "bob",
+      "isValid": false
     }
   ]
 }
\ No newline at end of file
Repository: goldibex/targaryen
Pull request #119 (2017-01-24 16:55:27)

fix: Properly handle computed member expressions
Rebase and fix tests for #114 


Patch:
diff --git a/lib/parser/statement/member.js b/lib/parser/statement/member.js
index 95c6ca6..2be9f5e 100644
--- a/lib/parser/statement/member.js
+++ b/lib/parser/statement/member.js
@@ -89,6 +89,7 @@ class MemberNode extends Node {
 
     if (this.computed) {
       this.property = Node.from(source, astNode.property, scope);
+      return;
     }
 
     try {


Test patch:
diff --git a/test/spec/lib/parser/rule.js b/test/spec/lib/parser/rule.js
index 19ea488..03c33a3 100644
--- a/test/spec/lib/parser/rule.js
+++ b/test/spec/lib/parser/rule.js
@@ -36,6 +36,12 @@ describe('Rule', function() {
 
     });
 
+    it('should provide global scope when infering a computed property type', function() {
+      expect(
+        () => parser.parse('root[$foo]() == null', ['$foo'])
+      ).to.throw(/Invalid property access/);
+    });
+
   });
 
   describe('#evaluate', function() {
Repository: goldibex/targaryen
Pull request #135 (2017-10-21 20:46:23)

fix: handle update operation with trailing slashes
fixes issue #134


Patch:
diff --git a/lib/paths.js b/lib/paths.js
index f885c8c..d222878 100644
--- a/lib/paths.js
+++ b/lib/paths.js
@@ -34,7 +34,7 @@ exports.trim = function(path) {
 
 exports.join = function(root, path) {
   root = exports.trim(root);
-  path = exports.trimLeft(path);
+  path = exports.trim(path);
 
   if (!root) {
     return path;


Test patch:
diff --git a/test/spec/lib/database/index.js b/test/spec/lib/database/index.js
index 7f57759..d78b1cc 100644
--- a/test/spec/lib/database/index.js
+++ b/test/spec/lib/database/index.js
@@ -1047,6 +1047,28 @@ describe('database', function() {
       expect(result.newData.val()).to.eql({foo: 1});
     });
 
+    it('should handle trailing slashes', function() {
+      const rules = {
+        rules: {
+          invites: {
+            $key: {
+              '.validate': 'newData.hasChildren(["createdAt"])',
+              createdAt: {
+                '.validate': 'newData.isNumber()'
+              }
+            },
+            '.write': true
+          }
+        }
+      };
+      const data = null;
+      const db = database.create(rules, data);
+
+      expect(db.update('/', {'invites/someKey': {createdAt: 1508598138982}}).allowed).to.be.true();
+      expect(db.update('/', {'invites/someKey': {createdAt: 'some time ago'}}).allowed).to.be.false();
+      expect(db.update('/', {'invites/': {createdAt: 1508598138982}}).allowed).to.be.false();
+    });
+
     it('should prune null node deeply', function() {
       const value = {a: {b: 2}};
       const rules = {rules: {'.write': true}};
Repository: goldibex/targaryen
Pull request #148 (2018-05-08 12:15:55)

Allow dot in literal regexp
They were parsed correctly but it failed to render them to a `RegExp` source.


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85d79b9..499529b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 3.1.0-beta.2 2018-05-07
+
+- Publish generated regexp parser; Thanks @a-xin for notice it.
+
 ## 3.1.0-beta.1 2018-05-06
 
 - Validate literal regular expression ([#146]).
diff --git a/lib/parser/regexp/.npmignore b/lib/parser/regexp/.npmignore
new file mode 100644
index 0000000..e69de29
diff --git a/lib/parser/regexp/index.js b/lib/parser/regexp/index.js
index de4182e..c087eaa 100644
--- a/lib/parser/regexp/index.js
+++ b/lib/parser/regexp/index.js
@@ -33,6 +33,7 @@ function render(ast, context) {
   case 'char':
     return escape(ast.value, context);
 
+  case 'dot':
   case 'number':
   case 'charset':
     return ast.value;
diff --git a/package.json b/package.json
index e354a05..c6ee2fe 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "targaryen",
-  "version": "3.1.0-beta.1",
+  "version": "3.1.0-beta.2",
   "description": "Test Firebase security rules without connecting to Firebase.",
   "bin": {
     "targaryen": "bin/targaryen",


Test patch:
diff --git a/test/spec/lib/parser/regexp.js b/test/spec/lib/parser/regexp.js
index 7e6b00d..95eb63a 100644
--- a/test/spec/lib/parser/regexp.js
+++ b/test/spec/lib/parser/regexp.js
@@ -261,6 +261,10 @@ describe('regexp', function() {
     title: 'charset',
     source: '\\wbc',
     expected: '\\wbc'
+  }, {
+    title: 'dot',
+    source: '.bc',
+    expected: '.bc'
   }, {
     title: 'positive set',
     source: '[-a-z]bc',