From a1bd3deb1d302f431902f6fafb04be2767f49bc2 Mon Sep 17 00:00:00 2001 From: Ravinou Date: Fri, 9 Jan 2026 13:13:43 +0100 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20trim=20ssh=20public=20key?= =?UTF-8?q?=20value=20in=20textarea=20#599?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Containers/RepoManage/RepoManage.tsx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Containers/RepoManage/RepoManage.tsx b/Containers/RepoManage/RepoManage.tsx index 4e4d924..b37f0cd 100644 --- a/Containers/RepoManage/RepoManage.tsx +++ b/Containers/RepoManage/RepoManage.tsx @@ -150,8 +150,12 @@ export default function RepoManage(props: RepoManageProps) { const formSubmitHandler = async (dataForm: DataForm) => { setIsLoading(true); start(); + + // Clean SSH key by removing leading/trailing whitespace and line breaks + const cleanedSSHKey = dataForm.sshkey.trim(); + //Verify that the SSH key is unique - if (!(await isSSHKeyUnique(dataForm.sshkey))) { + if (!(await isSSHKeyUnique(cleanedSSHKey))) { stop(); setIsLoading(false); return; @@ -161,7 +165,7 @@ export default function RepoManage(props: RepoManageProps) { const newRepo = { alias: dataForm.alias, storageSize: parseInt(dataForm.storageSize), - sshPublicKey: dataForm.sshkey, + sshPublicKey: cleanedSSHKey, comment: dataForm.comment, alert: dataForm.alert.value, lanCommand: dataForm.lanCommand, @@ -200,7 +204,7 @@ export default function RepoManage(props: RepoManageProps) { const dataEdited = { alias: dataForm.alias, storageSize: parseInt(dataForm.storageSize), - sshPublicKey: dataForm.sshkey, + sshPublicKey: cleanedSSHKey, comment: dataForm.comment, alert: dataForm.alert.value, lanCommand: dataForm.lanCommand, @@ -333,11 +337,14 @@ export default function RepoManage(props: RepoManageProps) { defaultValue={props.mode == 'edit' ? targetRepo?.sshPublicKey : undefined} {...register('sshkey', { required: 'SSH public key is required.', - pattern: { - value: - /^(ssh-ed25519 AAAAC3NzaC1lZDI1NTE5|sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29t|ssh-rsa AAAAB3NzaC1yc2)[0-9A-Za-z+/]+[=]{0,3}(\s.*)?$/, - message: - 'Invalid public key. The key needs to be in OpenSSH format (rsa, ed25519, ed25519-sk)', + validate: (value) => { + const trimmedValue = value.trim(); + const pattern = + /^(ssh-ed25519 AAAAC3NzaC1lZDI1NTE5|sk-ssh-ed25519@openssh.com AAAAGnNrLXNzaC1lZDI1NTE5QG9wZW5zc2guY29t|ssh-rsa AAAAB3NzaC1yc2)[0-9A-Za-z+/]+[=]{0,3}(\s.*)?$/; + return ( + pattern.test(trimmedValue) || + 'Invalid public key. The key needs to be in OpenSSH format (rsa, ed25519, ed25519-sk)' + ); }, })} />