-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(builder): Add packageref validation for name and variant size #1185
Conversation
|
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 978931a. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
packages/builder/src/package.ts
Outdated
@@ -89,6 +89,17 @@ export class PackageReference { | |||
} | |||
|
|||
static isValid(ref: string) { | |||
const pkgRef = new PackageReference(ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the error logic here so that I could run this function on the zod schema as a refine, however it seems wrong to add error logic to a boolean function. There's likely a better way to achieve this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this to add the error logic in the parse function of the package ref class, and add custom refinements in zod on the schema itself.
e89ce24
to
7c983a3
Compare
packages/builder/src/package.ts
Outdated
try { | ||
PackageReference.parse(ref); | ||
} catch (err) { | ||
return false; | ||
} | ||
return !!PackageReference.PACKAGE_REGEX.test(ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex is already being used inside the .parse
:
try { | |
PackageReference.parse(ref); | |
} catch (err) { | |
return false; | |
} | |
return !!PackageReference.PACKAGE_REGEX.test(ref); | |
try { | |
PackageReference.parse(ref); | |
return true; | |
} catch (err) { | |
return false; | |
} |
packages/builder/src/package.ts
Outdated
if (match.groups.version) res.version = match.groups.version; | ||
|
||
const versionSize = res.name.length; | ||
if (!(versionSize <= 32)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think versionSize > 32
is the same and easier to read
Added a validation on the package reference class that throws an error when name or variant size exceeds 32 bytes

fixes https://linear.app/usecannon/issue/CAN-376/verify-target-in-clone-step-isnt-too-long-to-publish-before-building