Skip to content

Commit

Permalink
Merge pull request #43 from michaellatman/devin/1733906661-fix-url-va…
Browse files Browse the repository at this point in the history
…lidation
  • Loading branch information
michaellatman authored Dec 11, 2024
2 parents 7fa56ee + 3872b8f commit 2ec87ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/scripts/pr-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ export function validateRequiredFields(pkg) {
console.log('Validating URLs...');
const urlFields = ['sourceUrl', 'homepage'];
for (const field of urlFields) {
try {
new URL(pkg[field]);
} catch (error) {
throw new Error(`Package ${pkg.name} has invalid ${field} URL: ${pkg[field]}`);
const url = pkg[field];
if (!url.startsWith('http://') && !url.startsWith('https://')) {
throw new Error(`Package ${pkg.name} has invalid ${field} URL: ${url} - must start with http:// or https://`);
}
}
}
Expand Down
42 changes: 42 additions & 0 deletions src/scripts/pr-check.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { validateRequiredFields } from './pr-check.js';

describe('validateRequiredFields', () => {
test('accepts valid GitHub URLs', () => {
const pkg = {
name: 'test-package',
description: 'Test package',
vendor: 'Test Vendor',
sourceUrl: 'https://github.com/owner/repo',
homepage: 'https://github.com/owner/repo',
license: 'MIT',
runtime: 'node'
};
expect(() => validateRequiredFields(pkg)).not.toThrow();
});

test('rejects invalid URLs without protocol', () => {
const pkg = {
name: 'test-package',
description: 'Test package',
vendor: 'Test Vendor',
sourceUrl: 'github.com/owner/repo',
homepage: 'https://github.com/owner/repo',
license: 'MIT',
runtime: 'node'
};
expect(() => validateRequiredFields(pkg)).toThrow(/invalid sourceUrl URL/);
});

test('accepts both http and https protocols', () => {
const pkg = {
name: 'test-package',
description: 'Test package',
vendor: 'Test Vendor',
sourceUrl: 'http://github.com/owner/repo',
homepage: 'https://github.com/owner/repo',
license: 'MIT',
runtime: 'node'
};
expect(() => validateRequiredFields(pkg)).not.toThrow();
});
});

0 comments on commit 2ec87ce

Please sign in to comment.