diff --git a/github-issue-to-markdown.html b/github-issue-to-markdown.html
index 4c3d36d..8678702 100644
--- a/github-issue-to-markdown.html
+++ b/github-issue-to-markdown.html
@@ -204,7 +204,12 @@
Convert GitHub issue to markdown
function parseGitHubUrl(url) {
try {
- const urlObj = new URL(url)
+ // Normalize URL by adding https:// if no protocol is present
+ let normalizedUrl = url.trim()
+ if (!normalizedUrl.match(/^https?:\/\//)) {
+ normalizedUrl = 'https://' + normalizedUrl
+ }
+ const urlObj = new URL(normalizedUrl)
const [, owner, repo, , number] = urlObj.pathname.split('/')
if (!owner || !repo || !number) {
throw new Error('Invalid URL format')
@@ -601,6 +606,16 @@ Convert GitHub issue to markdown
assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '123' })
})
+test('parseGitHubUrl: URL without protocol (adds https://)', () => {
+ const result = parseGitHubUrl('github.com/owner/repo/issues/123')
+ assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '123' })
+})
+
+test('parseGitHubUrl: URL with http:// protocol', () => {
+ const result = parseGitHubUrl('http://github.com/owner/repo/issues/456')
+ assertDeepEqual(result, { owner: 'owner', repo: 'repo', number: '456' })
+})
+
test('parseGitHubUrl: valid PR URL', () => {
const result = parseGitHubUrl('https://github.com/simonw/sqlite-utils/pull/456')
assertDeepEqual(result, { owner: 'simonw', repo: 'sqlite-utils', number: '456' })