{"record":{"id":"bf059b1766e682e8","repo":"coreybutler/nvm-windows","slug":"patch-number-must-not-contain-leading-zeroes-q","errorCode":null,"errorMessage":"Patch number must not contain leading zeroes %q","messagePattern":"Patch number must not contain leading zeroes %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/semver/semver.go","lineNumber":239,"sourceCode":"\t} else if preIndex == -1 && buildIndex != -1 {\n\t\tsubVersionIndex = buildIndex\n\t} else if preIndex == -1 && buildIndex == -1 {\n\t\tsubVersionIndex = len(parts[2])\n\t} else {\n\t\t// if there is no actual pr version but a hyphen inside the build meta data\n\t\tif buildIndex < preIndex {\n\t\t\tsubVersionIndex = buildIndex\n\t\t\tpreIndex = -1 // Build meta data before preIndex found implicates there are no prerelease versions\n\t\t} else {\n\t\t\tsubVersionIndex = preIndex\n\t\t}\n\t}\n\n\tif !containsOnly(parts[2][:subVersionIndex], numbers) {\n\t\treturn nil, fmt.Errorf(\"Invalid character(s) found in patch number %q\", parts[2][:subVersionIndex])\n\t}\n\tif hasLeadingZeroes(parts[2][:subVersionIndex]) {\n\t\treturn nil, fmt.Errorf(\"Patch number must not contain leading zeroes %q\", parts[2][:subVersionIndex])\n\t}\n\tpatch, err := strconv.ParseUint(parts[2][:subVersionIndex], 10, 64)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tv := &Version{}\n\tv.Major = major\n\tv.Minor = minor\n\tv.Patch = patch\n\n\t// There are PreRelease versions\n\tif preIndex != -1 {\n\t\tvar preRels string\n\t\tif buildIndex != -1 {\n\t\t\tpreRels = parts[2][subVersionIndex+1 : buildIndex]\n\t\t} else {\n\t\t\tpreRels = parts[2][subVersionIndex+1:]\n\t\t}","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/semver/semver.go#L221-L257","documentation":"Semver parse error enforcing strict SEMVER 2.0.0 compliance: the patch number has a leading zero (e.g. \"01\", \"007\"). hasLeadingZeroes(patch) returned true, which semver spec forbids because versions are numeric identifiers.","triggerScenarios":"semver.NewVersion(\"1.2.01\"), \"1.2.007\", or any patch segment matching /^0\\d+/ after the numeric-only check passes.","commonSituations":"Zero-padded version strings generated by scripts (e.g. dates or counters formatted with %02d), versions scraped from filenames or tags that pad segments, user-typed versions with padding.","solutions":["Strip leading zeroes from each numeric segment before parsing: strconv.FormatUint(strconv.ParseUint(seg,10,64))","Fix the generator producing zero-padded versions","Validate input against a strict semver regex before handing it to NewVersion"],"exampleFix":"// before\nv, err := semver.NewVersion(\"1.2.01\") // error: leading zeroes\n\n// after\nv, err := semver.NewVersion(\"1.2.1\")","handlingStrategy":"validation","validationCode":"func stripLeadingZeroes(seg string) (string, error) {\n    n, err := strconv.ParseUint(strings.TrimLeft(seg, \"0\"), 10, 64)\n    if err != nil { return \"\", err }\n    return strconv.FormatUint(n, 10), nil\n}","typeGuard":null,"tryCatchPattern":"if _, err := semver.NewVersion(v); err != nil && strings.Contains(err.Error(), \"leading zeroes\") {\n    v = normalizeSegments(v) // rewrite 01 -> 1 per segment, then retry\n    _, err = semver.NewVersion(v)\n}","preventionTips":["Never format version segments with %02d","Normalize external version strings through ParseUint/FormatUint before parsing","Add a semver-regex lint for generated release tags"],"tags":["semver","parsing","validation","leading-zero"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}