From 5fe513cd18c27753301b1088e6868af0c1209d63 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Mon, 7 Jul 2025 15:20:38 +0200 Subject: [PATCH] feat(tools): Added encoding when special characters used with username Closes https://github.com/espressif/esp-idf/issues/16229 --- tools/export_utils/shell_types.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/export_utils/shell_types.py b/tools/export_utils/shell_types.py index 82e3df61c1..112ede5755 100644 --- a/tools/export_utils/shell_types.py +++ b/tools/export_utils/shell_types.py @@ -1,5 +1,6 @@ # SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: Apache-2.0 +import base64 import getpass import os import re @@ -33,7 +34,15 @@ class Shell(): self.new_esp_idf_env = new_esp_idf_env try: - self.tmp_dir_path = Path(gettempdir()) / ('esp_idf_activate_' + getpass.getuser()) + username = getpass.getuser() + username_safe = ( + # If username contains special characters, base64-encode it + base64.urlsafe_b64encode(username.encode('utf-8')).decode('ascii').rstrip('=') + # Find characters that are not ASCII alphanumeric, dot, or dash + if re.search(r'[^\w.-]', username, flags=re.ASCII) + else username + ) + self.tmp_dir_path = Path(gettempdir()) / f'esp_idf_activate_{username_safe}' except Exception as e: self.tmp_dir_path = Path(gettempdir()) / 'esp_idf_activate' warn(f'Failed to get username with error: {e}. Using default temporary directory {self.tmp_dir_path}.')