protobufjs 7.5.5 → 7.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -237,12 +237,35 @@ util.longFromHash = function longFromHash(hash, unsigned) {
237
237
  function merge(dst, src, ifNotSet) { // used by converters
238
238
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
239
239
  if (dst[keys[i]] === undefined || !ifNotSet)
240
- dst[keys[i]] = src[keys[i]];
240
+ if (keys[i] !== "__proto__")
241
+ dst[keys[i]] = src[keys[i]];
241
242
  return dst;
242
243
  }
243
244
 
244
245
  util.merge = merge;
245
246
 
247
+ /**
248
+ * Recursion limit.
249
+ * @memberof util
250
+ * @type {number}
251
+ */
252
+ util.recursionLimit = 100;
253
+
254
+ /**
255
+ * Makes a property safe for assignment as an own property.
256
+ * @memberof util
257
+ * @param {Object.<string,*>} obj Object
258
+ * @param {string} key Property key
259
+ * @returns {undefined}
260
+ */
261
+ util.makeProp = function makeProp(obj, key) {
262
+ Object.defineProperty(obj, key, {
263
+ enumerable: true,
264
+ configurable: true,
265
+ writable: true
266
+ });
267
+ };
268
+
246
269
  /**
247
270
  * Converts the first character of a string to lower case.
248
271
  * @param {string} str String to convert
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ var patterns = exports;
4
+
5
+ patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
6
+ patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
7
+ patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
8
+ patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
package/src/util.js CHANGED
@@ -14,6 +14,10 @@ var Type, // cyclic
14
14
  util.codegen = require("@protobufjs/codegen");
15
15
  util.fetch = require("@protobufjs/fetch");
16
16
  util.path = require("@protobufjs/path");
17
+ util.patterns = require("./util/patterns");
18
+
19
+ var reservedRe = util.patterns.reservedRe,
20
+ unsafePropertyRe = util.patterns.unsafePropertyRe;
17
21
 
18
22
  /**
19
23
  * Node's fs module if available.
@@ -55,16 +59,13 @@ util.toObject = function toObject(array) {
55
59
  return object;
56
60
  };
57
61
 
58
- var safePropBackslashRe = /\\/g,
59
- safePropQuoteRe = /"/g;
60
-
61
62
  /**
62
63
  * Tests whether the specified name is a reserved word in JS.
63
64
  * @param {string} name Name to test
64
65
  * @returns {boolean} `true` if reserved, otherwise `false`
65
66
  */
66
67
  util.isReserved = function isReserved(name) {
67
- return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name);
68
+ return reservedRe.test(name);
68
69
  };
69
70
 
70
71
  /**
@@ -73,8 +74,8 @@ util.isReserved = function isReserved(name) {
73
74
  * @returns {string} Safe accessor
74
75
  */
75
76
  util.safeProp = function safeProp(prop) {
76
- if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))
77
- return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
77
+ if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
78
+ return "[" + JSON.stringify(prop) + "]";
78
79
  return "." + prop;
79
80
  };
80
81
 
@@ -177,9 +178,8 @@ util.decorateEnum = function decorateEnum(object) {
177
178
  util.setProperty = function setProperty(dst, path, value, ifNotSet) {
178
179
  function setProp(dst, path, value) {
179
180
  var part = path.shift();
180
- if (part === "__proto__" || part === "prototype") {
181
- return dst;
182
- }
181
+ if (unsafePropertyRe.test(part))
182
+ return dst;
183
183
  if (path.length > 0) {
184
184
  dst[part] = setProp(dst[part] || {}, path, value);
185
185
  } else {
package/src/verifier.js CHANGED
@@ -32,7 +32,7 @@ function genVerifyValue(gen, field, fieldIndex, ref) {
32
32
  } else {
33
33
  gen
34
34
  ("{")
35
- ("var e=types[%i].verify(%s);", fieldIndex, ref)
35
+ ("var e=types[%i].verify(%s,n+1);", fieldIndex, ref)
36
36
  ("if(e)")
37
37
  ("return%j+e", field.name + ".")
38
38
  ("}");
@@ -122,9 +122,12 @@ function genVerifyKey(gen, field, ref) {
122
122
  function verifier(mtype) {
123
123
  /* eslint-disable no-unexpected-multiline */
124
124
 
125
- var gen = util.codegen(["m"], mtype.name + "$verify")
125
+ var gen = util.codegen(["m", "n"], mtype.name + "$verify")
126
126
  ("if(typeof m!==\"object\"||m===null)")
127
- ("return%j", "object expected");
127
+ ("return%j", "object expected")
128
+ ("if(n===undefined)n=0")
129
+ ("if(n>util.recursionLimit)")
130
+ ("return%j", "maximum nesting depth exceeded");
128
131
  var oneofs = mtype.oneofsArray,
129
132
  seenFirstField = {};
130
133
  if (oneofs.length) gen
@@ -174,4 +177,4 @@ function verifier(mtype) {
174
177
  return gen
175
178
  ("return null");
176
179
  /* eslint-enable no-unexpected-multiline */
177
- }
180
+ }
package/src/wrappers.js CHANGED
@@ -38,7 +38,7 @@ var Message = require("./message");
38
38
  // Custom wrapper for Any
39
39
  wrappers[".google.protobuf.Any"] = {
40
40
 
41
- fromObject: function(object) {
41
+ fromObject: function(object, depth) {
42
42
 
43
43
  // unwrap value type if mapped
44
44
  if (object && object["@type"]) {
@@ -54,14 +54,15 @@ wrappers[".google.protobuf.Any"] = {
54
54
  if (type_url.indexOf("/") === -1) {
55
55
  type_url = "/" + type_url;
56
56
  }
57
+ var nextDepth = depth === undefined ? 1 : depth + 1;
57
58
  return this.create({
58
59
  type_url: type_url,
59
- value: type.encode(type.fromObject(object)).finish()
60
+ value: type.encode(type.fromObject(object, nextDepth)).finish()
60
61
  });
61
62
  }
62
63
  }
63
64
 
64
- return this.fromObject(object);
65
+ return this.fromObject(object, depth);
65
66
  },
66
67
 
67
68
  toObject: function(message, options) {