From c796cf400913124874d2d369d9b20a27b776e606 Mon Sep 17 00:00:00 2001 From: PaperCube Date: Tue, 13 Feb 2024 00:49:08 +0000 Subject: [PATCH] Fix "PEM header must end with -----" by standardizing CRLF --- lib/view/page/private_key/edit.dart | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/view/page/private_key/edit.dart b/lib/view/page/private_key/edit.dart index 4818d5a5..8ba6ada5 100644 --- a/lib/view/page/private_key/edit.dart +++ b/lib/view/page/private_key/edit.dart @@ -118,12 +118,16 @@ class _PrivateKeyEditPageState extends State { ); } + String _standardizeLineSeparators(String value) { + return value.replaceAll("\r\n", "\n").replaceAll("\r", "\n"); + } + Widget _buildFAB() { return FloatingActionButton( tooltip: l10n.save, onPressed: () async { final name = _nameController.text; - final key = _keyController.text.trim(); + final key = _standardizeLineSeparators(_keyController.text.trim()); final pwd = _pwdController.text; if (name.isEmpty || key.isEmpty) { context.showSnackBar(l10n.fieldMustNotEmpty); @@ -201,11 +205,8 @@ class _PrivateKeyEditPageState extends State { } final content = await file.readAsString(); - - /// Issue #7 - /// Replace all CRLF to LF - content.replaceAll('\r\n', '\n'); - _keyController.text = content; + // dartssh2 accepts only LF (but not CRLF or CR) + _keyController.text = _standardizeLineSeparators(content.trim()); }, child: Text(l10n.pickFile), ),