-
Notifications
You must be signed in to change notification settings - Fork 50
fix: validate skills new --price as non-negative integer (#457) #468
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,14 @@ const SKILL_TARGETS = { | |
| function slugify(s: string): string { | ||
| return s.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '').slice(0, 64) || 'my-skill'; | ||
| } | ||
| function validatePrice(raw: string): number { | ||
| const trimmed = raw.trim(); | ||
| if (!/^\d+$/.test(trimmed)) { | ||
| throw new Error(`Invalid --price "${raw}": must be a non-negative integer (sats). Got "${raw}".`); | ||
| } | ||
| return parseInt(trimmed, 10); | ||
| } | ||
|
|
||
| function q(s: string): string { return JSON.stringify(s); } | ||
| async function exists(path: string): Promise<boolean> { try { await access(path); return true; } catch { return false; } } | ||
| function frontmatterValue(text: string, key: string): string | undefined { | ||
|
|
@@ -356,10 +364,10 @@ skillsCmd | |
| tagline: opts.tagline, | ||
| category: opts.category, | ||
| tags: opts.tags.split(',').map(t => t.trim()).filter(Boolean).slice(0, 10), | ||
| price: Number.parseInt(opts.price, 10) || 0, | ||
| price: validatePrice(opts.price), | ||
| skillFile, | ||
| sourceUrl: opts.sourceUrl, | ||
| marketplaces: Object.fromEntries(MARKETPLACES.map(mp => [mp.id, { enabled: true, status: 'pending', command: 'command' in mp && mp.command ? mp.command({ name, title, description, tagline: opts.tagline, category: opts.category, tags: opts.tags.split(',').map(t => t.trim()).filter(Boolean).slice(0, 10), price: Number.parseInt(opts.price, 10) || 0, skillFile, sourceUrl: opts.sourceUrl, marketplaces: {} }) : undefined, note: 'note' in mp ? mp.note : undefined }])) as SkillManifest['marketplaces'], | ||
| marketplaces: Object.fromEntries(MARKETPLACES.map(mp => [mp.id, { enabled: true, status: 'pending', command: 'command' in mp && mp.command ? mp.command({ name, title, description, tagline: opts.tagline, category: opts.category, tags: opts.tags.split(',').map(t => t.trim()).filter(Boolean).slice(0, 10), price: validatePrice(opts.price), skillFile, sourceUrl: opts.sourceUrl, marketplaces: {} }) : undefined, note: 'note' in mp ? mp.note : undefined }])) as SkillManifest['marketplaces'], | ||
|
Comment on lines
+367
to
+370
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| }; | ||
| await mkdir(dirname(resolve(opts.out)), { recursive: true }); | ||
| await saveManifest(opts.out, manifest); | ||
|
|
||
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.
rawappears twice in the same message — once as"${raw}"afterInvalid --priceand again asGot "${raw}". The second occurrence adds no new information. If the intent is to distinguish the original input from the trimmed value, the second slot should referencetrimmed; otherwise, drop the trailingGot "${raw}"..Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!