mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-08-17 08:10:52 +03:00
refactor: Normalized branch name handling
This commit is contained in:
parent
d5053db0c3
commit
b7f355a9ca
@ -1,3 +1,7 @@
|
||||
export function normalizeBranchName(value: string) {
|
||||
return value.replace(/[^A-Za-z0-9_/.#]+/g, '-');
|
||||
export function normalizeBranchName(str: string) {
|
||||
let result = str.replace(/\s+/g, '-');
|
||||
|
||||
result = result.replace(/^[-/]+|[-/]+$/g, '');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -3,9 +3,16 @@ use gitbutler_tagged_string::TaggedString;
|
||||
pub use refname::{LocalRefname, Refname, RemoteRefname, VirtualRefname};
|
||||
use regex::Regex;
|
||||
|
||||
// ref function normalizeBranchName in branch.ts
|
||||
pub fn normalize_branch_name(name: &str) -> String {
|
||||
let pattern = Regex::new("[^A-Za-z0-9_/.#]+").unwrap();
|
||||
pattern.replace_all(name, "-").to_string()
|
||||
let pattern = Regex::new(r"\s+").unwrap();
|
||||
let mut result = pattern.replace_all(name, "-").to_string();
|
||||
|
||||
// Remove leading and trailing hyphens and slashes
|
||||
let trim_pattern = Regex::new(r"^[-/]+|[-/]+$").unwrap();
|
||||
result = trim_pattern.replace_all(&result, "").to_string();
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub struct _ReferenceName;
|
||||
|
Loading…
Reference in New Issue
Block a user