mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 05:04:33 +02:00
Merge branch 'fix/username_special_characters_v5.4' into 'release/v5.4'
feat(tools): Added encoding when special characters used with username (v5.4) See merge request espressif/esp-idf!40569
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
import base64
|
||||||
import getpass
|
import getpass
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@@ -33,7 +34,15 @@ class Shell():
|
|||||||
self.new_esp_idf_env = new_esp_idf_env
|
self.new_esp_idf_env = new_esp_idf_env
|
||||||
|
|
||||||
try:
|
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:
|
except Exception as e:
|
||||||
self.tmp_dir_path = Path(gettempdir()) / 'esp_idf_activate'
|
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}.')
|
warn(f'Failed to get username with error: {e}. Using default temporary directory {self.tmp_dir_path}.')
|
||||||
|
Reference in New Issue
Block a user