@@ -6,6 +6,14 @@ const https = require('https');
66const { isValidHttpUrl } = require ( '../lib/cli-utils' ) ;
77const { MAX_SKILLS_ZIP_UPLOAD_SIZE , importSkillsFromZipFile } = require ( './skills' ) ;
88
9+ function decodeUrlPathPart ( part ) {
10+ try {
11+ return decodeURIComponent ( part ) ;
12+ } catch ( _ ) {
13+ return part ;
14+ }
15+ }
16+
917function parseGithubRepoFromUrl ( inputUrl ) {
1018 const raw = typeof inputUrl === 'string' ? inputUrl . trim ( ) : '' ;
1119 if ( ! raw ) return null ;
@@ -21,7 +29,7 @@ function parseGithubRepoFromUrl(inputUrl) {
2129 if ( parsed . hostname !== 'github.com' ) {
2230 return null ;
2331 }
24- const parts = parsed . pathname . split ( '/' ) . filter ( Boolean ) ;
32+ const parts = parsed . pathname . split ( '/' ) . filter ( Boolean ) . map ( decodeUrlPathPart ) ;
2533 if ( parts . length < 2 ) return null ;
2634 const owner = parts [ 0 ] ;
2735 const repoPart = parts [ 1 ] || '' ;
@@ -38,20 +46,27 @@ function buildGithubArchiveZipBase(repoInfo) {
3846 return `https://github.com/${ encodeURIComponent ( repoInfo . owner ) } /${ encodeURIComponent ( repoInfo . repo ) } /archive/refs` ;
3947}
4048
49+ function encodeGithubRefPath ( ref ) {
50+ return String ( ref || '' )
51+ . split ( '/' )
52+ . map ( part => encodeURIComponent ( part ) )
53+ . join ( '/' ) ;
54+ }
55+
4156function resolveGithubArchiveZipUrl ( inputUrl ) {
4257 const repoInfo = parseGithubRepoFromUrl ( inputUrl ) ;
4358 if ( ! repoInfo ) return '' ;
4459 const base = buildGithubArchiveZipBase ( repoInfo ) ;
4560 const ref = repoInfo . ref || 'main' ;
46- return `${ base } /heads/${ encodeURIComponent ( ref ) } .zip` ;
61+ return `${ base } /heads/${ encodeGithubRefPath ( ref ) } .zip` ;
4762}
4863
4964function buildGithubArchiveZipCandidates ( inputUrl ) {
5065 const repoInfo = parseGithubRepoFromUrl ( inputUrl ) ;
5166 if ( ! repoInfo ) return [ ] ;
5267 const base = buildGithubArchiveZipBase ( repoInfo ) ;
5368 if ( repoInfo . ref ) {
54- const ref = encodeURIComponent ( repoInfo . ref ) ;
69+ const ref = encodeGithubRefPath ( repoInfo . ref ) ;
5570 return [
5671 `${ base } /heads/${ ref } .zip` ,
5772 `${ base } /tags/${ ref } .zip`
@@ -256,7 +271,7 @@ async function cmdImportSkills(argv = []) {
256271 printImportSkillsUsage ( ) ;
257272 return ;
258273 }
259- if ( ! options . url || options . url . trim ( ) . startsWith ( '--' ) ) {
274+ if ( ! options . url ) {
260275 printImportSkillsUsage ( ) ;
261276 throw new Error ( '错误: 缺少 URL(例如: https://github.com/<owner>/<repo>/archive/refs/heads/main.zip)' ) ;
262277 }
0 commit comments