Skip to content
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: update URL validation to handle GitHub URLs properly #43

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
});
});
Loading