Skip to content

Commit f070dde

Browse files
authoredApr 11, 2022
fix: ensure SemVer instance passed to inc are not modified (#427)
1 parent 4571a1a commit f070dde

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed
 

‎functions/inc.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ const inc = (version, release, options, identifier) => {
77
}
88

99
try {
10-
return new SemVer(version, options).inc(release, identifier).version
10+
return new SemVer(
11+
version instanceof SemVer ? version.version : version,
12+
options
13+
).inc(release, identifier).version
1114
} catch (er) {
1215
return null
1316
}

‎test/functions/inc.js

+10
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,20 @@ test('increment versions test', (t) => {
1010
t.equal(found, wanted, `${cmd} === ${wanted}`)
1111

1212
const parsed = parse(pre, options)
13+
const parsedAsInput = parse(pre, options)
1314
if (wanted) {
1415
parsed.inc(what, id)
1516
t.equal(parsed.version, wanted, `${cmd} object version updated`)
1617
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)
18+
19+
const preIncObject = JSON.stringify(parsedAsInput)
20+
inc(parsedAsInput, what, options, id)
21+
const postIncObject = JSON.stringify(parsedAsInput)
22+
t.equal(
23+
postIncObject,
24+
preIncObject,
25+
`${cmd} didn't modify its input`
26+
)
1727
} else if (parsed) {
1828
t.throws(() => {
1929
parsed.inc(what, id)

0 commit comments

Comments
 (0)
Please sign in to comment.