aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/repo-common.ts
diff options
context:
space:
mode:
Diffstat (limited to 'web_src/js/features/repo-common.ts')
-rw-r--r--web_src/js/features/repo-common.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/web_src/js/features/repo-common.ts b/web_src/js/features/repo-common.ts
index 4362a2c713..ebb6881c67 100644
--- a/web_src/js/features/repo-common.ts
+++ b/web_src/js/features/repo-common.ts
@@ -159,3 +159,19 @@ export async function updateIssuesMeta(url: string, action: string, issue_ids: s
console.error(error);
}
}
+
+export function sanitizeRepoName(name: string): string {
+ name = name.trim().replace(/[^-.\w]/g, '-');
+ for (let lastName = ''; lastName !== name;) {
+ lastName = name;
+ name = name.replace(/\.+$/g, '');
+ name = name.replace(/\.{2,}/g, '.');
+ for (const ext of ['.git', '.wiki', '.rss', '.atom']) {
+ if (name.endsWith(ext)) {
+ name = name.substring(0, name.length - ext.length);
+ }
+ }
+ }
+ if (['.', '..', '-'].includes(name)) name = '';
+ return name;
+}