Просмотр исходного кода

escape branch name of plugin repository

Ryu Sato 2 лет назад
Родитель
Сommit
9e2c0c6221
1 измененных файлов с 4 добавлено и 3 удалено
  1. 4 3
      apps/app/src/features/growi-plugin/server/models/vo/github-url.ts

+ 4 - 3
apps/app/src/features/growi-plugin/server/models/vo/github-url.ts

@@ -2,8 +2,8 @@ import sanitize from 'sanitize-filename';
 
 // https://regex101.com/r/fK2rV3/1
 const githubReposIdPattern = new RegExp(/^\/([^/]+)\/([^/]+)$/);
-// https://regex101.com/r/DOVpOT/1
-const sanitizeChars = new RegExp(/[/|"'<>]+/g);
+// https://regex101.com/r/YhZVsj/1
+const sanitizeChars = new RegExp(/[^a-zA-Z_.]+/g);
 
 export class GitHubUrl {
 
@@ -26,7 +26,8 @@ export class GitHubUrl {
   }
 
   get archiveUrl(): string {
-    const ghUrl = new URL(`/${this.organizationName}/${this.reposName}/archive/refs/heads/${this.branchName}.zip`, 'https://github.com');
+    const encodedBranchName = encodeURIComponent(this.branchName);
+    const ghUrl = new URL(`/${this.organizationName}/${this.reposName}/archive/refs/heads/${encodedBranchName}.zip`, 'https://github.com');
     return ghUrl.toString();
   }