Skip to content

Commit cc991a0

Browse files
committed
CLI: Use correct safeProp in json-module target, see #956
1 parent d130b52 commit cc991a0

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

cli/targets/json-module.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,25 @@ var protobuf = require("../..");
77

88
json_module.description = "JSON representation as a module";
99

10+
function jsonSafeProp(json) {
11+
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
12+
return protobuf.util.safeProp($2).charAt(0) === "."
13+
? $1 + $2 + ":"
14+
: $0;
15+
});
16+
}
17+
1018
function json_module(root, options, callback) {
1119
try {
12-
var rootProp = util.safeProp(options.root || "default");
20+
var rootProp = protobuf.util.safeProp(options.root || "default");
1321
var output = [
1422
(options.es6 ? "const" : "var") + " $root = ($protobuf.roots" + rootProp + " || ($protobuf.roots" + rootProp + " = new $protobuf.Root()))\n"
1523
];
1624
if (root.options) {
17-
var optionsJson = util.jsonSafeProp(JSON.stringify(root.options, null, 2));
25+
var optionsJson = jsonSafeProp(JSON.stringify(root.options, null, 2));
1826
output.push(".setOptions(" + optionsJson + ")\n");
1927
}
20-
var json = util.jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
28+
var json = jsonSafeProp(JSON.stringify(root.nested, null, 2).trim());
2129
output.push(".addJSON(" + json + ");");
2230
output = util.wrap(output.join(""), protobuf.util.merge({ dependency: "protobufjs/light" }, options));
2331
process.nextTick(function() {

cli/util.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,3 @@ exports.pad = function(str, len, l) {
181181
return str;
182182
};
183183

184-
exports.jsonSafeProp = function(json) {
185-
return json.replace(/^( +)"(\w+)":/mg, function($0, $1, $2) {
186-
return exports.safeProp($2).charAt(0) === "."
187-
? $1 + $2 + ":"
188-
: $0;
189-
});
190-
};

0 commit comments

Comments
 (0)