Browse files

Allow invalid json in already-installed packages

  • Loading branch information...
1 parent e7e5292 commit 80cd4bdd070bd4d61d259db8b89f84b796234887 @isaacs isaacs committed Feb 21, 2011
Showing with 19 additions and 5 deletions.
  1. +19 −5 lib/utils/read-json.js
View
24 lib/utils/read-json.js
@@ -70,14 +70,28 @@ function processJsonString (opts, cb) { return function (er, jsonString) {
try {
json = JSON.parse(jsonString)
} catch (ex) {
- var e = new Error(
- "Failed to parse json\n"+ex.message)
- e.errno = npm.EJSONPARSE
- if (cb) return cb(e)
- throw e
+ if (opts.file && opts.file.indexOf(npm.dir) === 0) {
+ try {
+ json = require("vm").runInNewContext("(\n"+jsonString+"\n)")
+ log.error(ex, "parse error "+opts.file)
+ } catch (ex2) {
+ return jsonParseFail(ex, cb)
+ }
+ } else {
+ return jsonParseFail(ex, cb)
+ }
}
return processObject(opts, cb)(er, json)
}}
+
+function jsonParseFail (ex, cb) {
+ var e = new Error(
+ "Failed to parse json\n"+ex.message)
+ e.errno = npm.EJSONPARSE
+ if (cb) return cb(e)
+ throw e
+}
+
function processObject (opts, cb) { return function (er, json) {
// slashes would be a security risk.

0 comments on commit 80cd4bd

Please sign in to comment.