From 4662f4feacaf6e99e8e163829a7a78fb7aeef717 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tim-Niclas=20Oelschl=C3=A4ger?=
<72873130+zokkis@users.noreply.github.com>
Date: Sun, 25 Feb 2024 15:31:15 +0100
Subject: [PATCH] enforce maxlength in frontend (#29389)
Set maxlength attribute in frontend
to long file-name
![image](https://github.com/go-gitea/gitea/assets/72873130/15111614-55ab-4583-acb2-15c25997601d)
![image](https://github.com/go-gitea/gitea/assets/72873130/4105ddd8-4973-4da8-b3ab-4cfae1b45554)
(same for branch-name and commit-summary)
(cherry picked from commit 756b952c52f1efbb137df36d5b97b370c8a45565)
---
templates/repo/editor/commit_form.tmpl | 4 ++--
templates/repo/editor/edit.tmpl | 2 +-
templates/repo/editor/patch.tmpl | 2 +-
templates/repo/editor/upload.tmpl | 2 +-
web_src/js/utils.js | 7 ++++---
5 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/templates/repo/editor/commit_form.tmpl b/templates/repo/editor/commit_form.tmpl
index 2c9bdb44b5..72af3e9ef3 100644
--- a/templates/repo/editor/commit_form.tmpl
+++ b/templates/repo/editor/commit_form.tmpl
@@ -9,7 +9,7 @@
{{ctx.Locale.Tr "repo.editor.commit_changes"}}
{{- end}}
-
+
@@ -60,7 +60,7 @@
diff --git a/templates/repo/editor/edit.tmpl b/templates/repo/editor/edit.tmpl
index cfc266731b..a6dce81c08 100644
--- a/templates/repo/editor/edit.tmpl
+++ b/templates/repo/editor/edit.tmpl
@@ -15,7 +15,7 @@
{{range $i, $v := .TreeNames}}
/
{{if eq $i $l}}
-
+
{{svg "octicon-info"}}
{{else}}
{{$v}}
diff --git a/templates/repo/editor/patch.tmpl b/templates/repo/editor/patch.tmpl
index b9ca530058..3de219014b 100644
--- a/templates/repo/editor/patch.tmpl
+++ b/templates/repo/editor/patch.tmpl
@@ -15,7 +15,7 @@
{{.BranchName}}
{{ctx.Locale.Tr "repo.editor.or"}} {{ctx.Locale.Tr "repo.editor.cancel_lower"}}
-
+
diff --git a/templates/repo/editor/upload.tmpl b/templates/repo/editor/upload.tmpl
index d362a5602a..0a7c49dae3 100644
--- a/templates/repo/editor/upload.tmpl
+++ b/templates/repo/editor/upload.tmpl
@@ -13,7 +13,7 @@
{{range $i, $v := .TreeNames}}
/
{{if eq $i $l}}
-
+
{{svg "octicon-info"}}
{{else}}
{{$v}}
diff --git a/web_src/js/utils.js b/web_src/js/utils.js
index 3a2694335f..ce0fb66343 100644
--- a/web_src/js/utils.js
+++ b/web_src/js/utils.js
@@ -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