Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Change generation of git branch names to only allow `[a-zA-Z\-_]`

Klaus Zandersfe026347d70f
diff --git a/modules/github_integration/frontend/module/git-actions/git-actions.service.spec.ts b/modules/github_integration/frontend/module/git-actions/git-actions.service.spec.ts
index fd033d7081f..c6fa19e2f3f 100644
--- a/modules/github_integration/frontend/module/git-actions/git-actions.service.spec.ts
+++ b/modules/github_integration/frontend/module/git-actions/git-actions.service.spec.ts
@@ -66,7 +66,7 @@ describe('GitActionsService', function() {
});
- it('it produces a branch name, commit message, and a git command', () => {
+ it('produces a branch name, commit message, and a git command', () => {
const wp = createWorkPackage();
expect(service.branchName(wp)).toEqual('user-story/42-find-the-question');
expect(service.commitMessage(wp)).toEqual(`[#42] Find the question
diff --git a/modules/github_integration/frontend/module/git-actions/git-actions.service.ts b/modules/github_integration/frontend/module/git-actions/git-actions.service.ts
index eeece1315e5..980b5958bd5 100644
--- a/modules/github_integration/frontend/module/git-actions/git-actions.service.ts
+++ b/modules/github_integration/frontend/module/git-actions/git-actions.service.ts
@@ -36,14 +36,12 @@ export class GitActionsService {
// See https://stackoverflow.com/a/3651867 for how these rules came in.
// This sanitization tries to be harsher than those rules
return str
- .replace(/&/g, 'and ') // & becomes and
- .replace(/ +/g, '-') // Spaces become dashes
- .replace(/[\x00-\x1F]/g, '') // ASCII control characters are out
- .replace(/\x7F/g, '') // DEL is out
- .replace(/[#\\\/\?\*\~\^\:\{\}@\.\[\]'"]/g, '') // Some other characters with special rules are out
- .replace(/^[-]+/g, '') // Dashes at the start are removed
- .replace(/[-]+$/g, '') // Dashes at the end are removed
- .replace(/-+/g, '-') // Multiple dashes in a row are deduped
+ .replace(/&/g, "and ") // & becomes and
+ .replace(/ +/g, "-") // Spaces become dashes
+ .replace(/[^\w\-]+/g, "") // Remove any non ascii characters as they might make trouble in some tools
+ .replace(/^[-]+/g, "") // Dashes at the start are removed
+ .replace(/[-]+$/g, "") // Dashes at the end are removed
+ .replace(/-+/g, "-") // Multiple dashes in a row are deduped
.trim();
}
diff --git a/modules/gitlab_integration/frontend/module/git-actions/git-actions.service.ts b/modules/gitlab_integration/frontend/module/git-actions/git-actions.service.ts
index e08d336b4e7..63e612ebc2b 100644
--- a/modules/gitlab_integration/frontend/module/git-actions/git-actions.service.ts
+++ b/modules/gitlab_integration/frontend/module/git-actions/git-actions.service.ts
@@ -39,14 +39,12 @@ export class GitActionsService {
// See https://stackoverflow.com/a/3651867 for how these rules came in.
// This sanitization tries to be harsher than those rules
return str
- .replace(/&/g, 'and ') // & becomes and
- .replace(/ +/g, '-') // Spaces become dashes
- .replace(/[\x00-\x1F]/g, '') // ASCII control characters are out
- .replace(/\x7F/g, '') // DEL is out
- .replace(/[#\\\/\?\*\~\^\:\{\}@\.\[\]'"]/g, '') // Some other characters with special rules are out
- .replace(/^[-]+/g, '') // Dashes at the start are removed
- .replace(/[-]+$/g, '') // Dashes at the end are removed
- .replace(/-+/g, '-') // Multiple dashes in a row are deduped
+ .replace(/&/g, "and ") // & becomes and
+ .replace(/ +/g, "-") // Spaces become dashes
+ .replace(/[^\w\-]+/g, "") // Remove any non ascii characters as they might make trouble in some tools
+ .replace(/^[-]+/g, "") // Dashes at the start are removed
+ .replace(/[-]+$/g, "") // Dashes at the end are removed
+ .replace(/-+/g, "-") // Multiple dashes in a row are deduped
.trim();
}