[Pkg-javascript-commits] [node-asn1.js] 180/202: node: improve tracking

Bastien Roucariès rouca at moszumanska.debian.org
Thu Apr 20 19:19:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-asn1.js.

commit b7a3bd06a0028dfeadde65895d8037589182a45f
Author: Fedor Indutny <fedor at indutny.com>
Date:   Mon Jul 11 00:25:48 2016 -0400

    node: improve tracking
---
 lib/asn1/base/node.js     | 15 +++++++++------
 lib/asn1/base/reporter.js |  8 +++++++-
 test/tracking-test.js     | 31 +++++++++++++++++++------------
 3 files changed, 35 insertions(+), 19 deletions(-)

diff --git a/lib/asn1/base/node.js b/lib/asn1/base/node.js
index 4c7943c..9b771d0 100644
--- a/lib/asn1/base/node.js
+++ b/lib/asn1/base/node.js
@@ -278,7 +278,7 @@ Node.prototype._decode = function decode(input, options) {
   var result = state['default'];
   var present = true;
 
-  var prevKey;
+  var prevKey = null;
   if (state.key !== null)
     prevKey = input.enterKey(state.key);
 
@@ -347,6 +347,12 @@ Node.prototype._decode = function decode(input, options) {
         input = body;
     }
 
+    if (options && options.track && state.tag !== null)
+      options.track(input.path(), start, input.length, 'tagged');
+
+    if (options && options.track && state.tag !== null)
+      options.track(input.path(), input.offset, input.length, 'content');
+
     // Select proper method for tag
     if (state.any)
       result = result;
@@ -373,11 +379,6 @@ Node.prototype._decode = function decode(input, options) {
       result = this._getUse(state.contains, input._reporterState.obj)
           ._decode(data, options);
     }
-
-    var end = input.offset;
-
-    if (options && options.track)
-      options.track(input.path(), start, end);
   }
 
   // Pop object
@@ -387,6 +388,8 @@ Node.prototype._decode = function decode(input, options) {
   // Set key
   if (state.key !== null && (result !== null || present === true))
     input.leaveKey(prevKey, state.key, result);
+  else if (prevKey !== null)
+    input.exitKey(prevKey);
 
   return result;
 };
diff --git a/lib/asn1/base/reporter.js b/lib/asn1/base/reporter.js
index 287655f..ec8b8b8 100644
--- a/lib/asn1/base/reporter.js
+++ b/lib/asn1/base/reporter.js
@@ -31,10 +31,16 @@ Reporter.prototype.enterKey = function enterKey(key) {
   return this._reporterState.path.push(key);
 };
 
-Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
+Reporter.prototype.exitKey = function exitKey(index) {
   var state = this._reporterState;
 
   state.path = state.path.slice(0, index - 1);
+};
+
+Reporter.prototype.leaveKey = function leaveKey(index, key, value) {
+  var state = this._reporterState;
+
+  this.exitKey(index);
   if (state.obj !== null)
     state.obj[key] = value;
 };
diff --git a/test/tracking-test.js b/test/tracking-test.js
index 1d0a273..1f9b4f6 100644
--- a/test/tracking-test.js
+++ b/test/tracking-test.js
@@ -24,24 +24,31 @@ describe('asn1.js tracking', function() {
       b: { x: 3, y: 4 }
     };
 
-    var tracked = {};
+    var tracked = [];
 
     var encoded = A.encode(input, 'der');
     var decoded = A.decode(encoded, 'der', {
-      track: function(path, start, end) {
-        tracked[path] = [ start, end ];
+      track: function(path, start, end, type) {
+        tracked.push([ type, path, start, end ]);
       }
     });
 
     jsonEqual(input, decoded);
-    assert.deepEqual(tracked, {
-      '': [ 0, 20 ],
-      a: [ 4, 12 ],
-      'a/x': [ 6, 8 ],
-      'a/y': [ 9, 11 ],
-       b: [ 12, 20 ],
-      'b/x': [ 14, 16 ],
-      'b/y': [ 17, 19 ]
-    });
+    assert.deepEqual(tracked, [
+      [ "tagged", "", 0, 20 ],
+      [ "content", "", 2, 20 ],
+      [ "tagged", "a", 4, 12 ],
+      [ "content", "a", 6, 12 ],
+      [ "tagged", "a/x", 6, 9 ],
+      [ "content", "a/x", 8, 9 ],
+      [ "tagged", "a/y", 9, 12 ],
+      [ "content", "a/y", 11, 12 ],
+      [ "tagged", "b", 12, 20 ],
+      [ "content", "b", 14, 20 ],
+      [ "tagged", "b/x", 14, 17 ],
+      [ "content", "b/x", 16, 17 ],
+      [ "tagged", "b/y", 17, 20 ],
+      [ "content", "b/y", 19, 20 ]
+    ]);
   });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-asn1.js.git



More information about the Pkg-javascript-commits mailing list