Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

guarding against undefined passed to JSON.stringify #171

Open
wants to merge 1 commit into
base: latest
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function putFirst (registry, data, tarbuffer, access, auth, cb) {

if (!auth.token) {
root.maintainers = [{ name: auth.username, email: auth.email }]
data.maintainers = JSON.parse(JSON.stringify(root.maintainers))
data.maintainers = root.maintainers === undefined ? undefined : JSON.parse(JSON.stringify(root.maintainers))
}

root.versions[ data.version ] = data
Expand Down Expand Up @@ -173,7 +173,7 @@ function putNext (registry, newVersion, root, current, auth, cb) {
current[i] = root[i]
}
}
var maint = JSON.parse(JSON.stringify(root.maintainers))
var maint = root.maintainers === undefined ? undefined : JSON.parse(JSON.stringify(root.maintainers))
root.versions[newVersion].maintainers = maint

var uri = url.resolve(registry, escaped(root.name))
Expand Down
2 changes: 1 addition & 1 deletion test/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ test('publish call contract', function (t) {
)

t.test('malformed semver in publish', function (t) {
var metadata = JSON.parse(JSON.stringify(METADATA))
var metadata = METADATA === undefined ? undefined : JSON.parse(JSON.stringify(METADATA))
metadata.version = '%!@#$'
var params = {
metadata: metadata,
Expand Down