Fix some frontend bugs related to folder naming
This commit is contained in:
parent
6ba592a84e
commit
6f8d52695c
2 changed files with 22 additions and 8 deletions
|
|
@ -61,17 +61,25 @@
|
|||
);
|
||||
|
||||
// Match backend's sanitize_folder_name logic for video path construction
|
||||
// Must exactly replicate src/utils.rs sanitize_folder_name
|
||||
function sanitizeFolderName(name, id) {
|
||||
const base = name && name.trim() ? name : id;
|
||||
|
||||
// Remove accents by decomposing to NFD and filtering combining marks
|
||||
const withoutAccents = base.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
|
||||
// Convert to lowercase and replace unsafe characters with underscores
|
||||
let sanitized = '';
|
||||
for (const c of base) {
|
||||
if (/^[\p{L}\p{N}\-_ ]$/u.test(c)) {
|
||||
for (const c of withoutAccents.toLowerCase()) {
|
||||
if (/^[a-z0-9\-_]$/.test(c)) {
|
||||
sanitized += c;
|
||||
} else {
|
||||
sanitized += '_';
|
||||
}
|
||||
}
|
||||
sanitized = sanitized.trim();
|
||||
|
||||
// Trim whitespace and underscores, then limit length
|
||||
sanitized = sanitized.replace(/^[\s_]+|[\s_]+$/g, '');
|
||||
return sanitized.length > 50 ? sanitized.slice(0, 50) : sanitized;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,19 +11,25 @@
|
|||
);
|
||||
|
||||
// Match backend's sanitize_folder_name logic
|
||||
// Uses Unicode-aware regex to match Rust's is_alphanumeric()
|
||||
// Must exactly replicate src/utils.rs sanitize_folder_name
|
||||
function sanitizeFolderName(name, id) {
|
||||
const base = name && name.trim() ? name : id;
|
||||
|
||||
// Remove accents by decomposing to NFD and filtering combining marks
|
||||
const withoutAccents = base.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||
|
||||
// Convert to lowercase and replace unsafe characters with underscores
|
||||
let sanitized = '';
|
||||
for (const c of base) {
|
||||
// \p{L} = Unicode letter, \p{N} = Unicode number (matches Rust's is_alphanumeric)
|
||||
if (/^[\p{L}\p{N}\-_ ]$/u.test(c)) {
|
||||
for (const c of withoutAccents.toLowerCase()) {
|
||||
if (/^[a-z0-9\-_]$/.test(c)) {
|
||||
sanitized += c;
|
||||
} else {
|
||||
sanitized += '_';
|
||||
}
|
||||
}
|
||||
sanitized = sanitized.trim();
|
||||
|
||||
// Trim whitespace and underscores, then limit length
|
||||
sanitized = sanitized.replace(/^[\s_]+|[\s_]+$/g, '');
|
||||
return sanitized.length > 50 ? sanitized.slice(0, 50) : sanitized;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue