@@ -30,8 +30,23 @@ export function computeBackportBranches(
3030 latestTag : string ,
3131 oldestSupportedMajorVersion : number ,
3232) : BackportInfo {
33- const majorVersionNumber = Number . parseInt ( majorVersion . substring ( 1 ) ) ;
34- const latestTagMajor = Number . parseInt ( latestTag . split ( "." ) [ 0 ] . substring ( 1 ) ) ;
33+ // Perform some sanity checks on the inputs.
34+ // For `majorVersion`, we expect exactly `vN` for some `N`.
35+ const majorVersionMatch = majorVersion . match ( / ^ v ( \d + ) $ / ) ;
36+ if ( ! majorVersionMatch ) {
37+ throw new Error ( "--major-version value must be in `vN` format." ) ;
38+ }
39+
40+ // For latestTag, we expect something starting with `vN.M.P`
41+ const latestTagMatch = latestTag . match ( / ^ v ( \d + ) \. \d + \. \d + / ) ;
42+ if ( ! latestTagMatch ) {
43+ throw new Error (
44+ `--latest-tag value must be in 'vN.M.P' format, but '${ latestTag } ' is not.` ,
45+ ) ;
46+ }
47+
48+ const majorVersionNumber = Number . parseInt ( majorVersionMatch [ 1 ] ) ;
49+ const latestTagMajor = Number . parseInt ( latestTagMatch [ 1 ] ) ;
3550
3651 // If this is a primary release, we backport to all supported branches,
3752 // so we check whether the majorVersion taken from the package.json
@@ -60,11 +75,11 @@ export function computeBackportBranches(
6075async function main ( ) {
6176 const { values : options } = parseArgs ( {
6277 options : {
63- // The major version of the release
78+ // The major version of the release in `vN` format (e.g. `v4`).
6479 "major-version" : {
6580 type : "string" ,
6681 } ,
67- // The most recent tag published to the repository
82+ // The most recent tag published to the repository (e.g. `v4.28.0`).
6883 "latest-tag" : {
6984 type : "string" ,
7085 } ,
0 commit comments