1
0
Fork 0
forked from forgejo/forgejo

enforce maxlength in frontend (#29389) (#29396)

Backport #29389 by @zokkis

Set maxlength attribute in frontend

to long file-name

![image](15111614-55ab-4583-acb2-15c25997601d)

![image](4105ddd8-4973-4da8-b3ab-4cfae1b45554)
(same for branch-name and commit-summary)

Co-authored-by: Tim-Niclas Oelschläger <72873130+zokkis@users.noreply.github.com>
(cherry picked from commit 0b3d6c399c88e42e827f422dc4c8458f0d20c613)
This commit is contained in:
Giteabot 2024-02-25 22:56:44 +08:00 committed by Earl Warren
parent 2c802fc8f0
commit 40c3a1d2ea
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
5 changed files with 9 additions and 8 deletions

View file

@ -2,13 +2,14 @@ import {encode, decode} from 'uint8-to-base64';
// transform /path/to/file.ext to file.ext
export function basename(path = '') {
return path ? path.replace(/^.*\//, '') : '';
const lastSlashIndex = path.lastIndexOf('/');
return lastSlashIndex < 0 ? path : path.substring(lastSlashIndex + 1);
}
// transform /path/to/file.ext to .ext
export function extname(path = '') {
const [_, ext] = /.+(\.[^.]+)$/.exec(path) || [];
return ext || '';
const lastPointIndex = path.lastIndexOf('.');
return lastPointIndex < 0 ? '' : path.substring(lastPointIndex);
}
// test whether a variable is an object