diff --git a/docs/en_US/release_notes_4_25.rst b/docs/en_US/release_notes_4_25.rst index ae18a9984..9e03e18cf 100644 --- a/docs/en_US/release_notes_4_25.rst +++ b/docs/en_US/release_notes_4_25.rst @@ -23,6 +23,7 @@ Housekeeping Bug fixes ********* +| `Issue #3767 `_ - Ensure that the original file format should be retained when saving the same file in SQL editor. | `Issue #4810 `_ - Fixed an issue where the user is not able to save the new row if the table is empty. | `Issue #5490 `_ - Make the runtime configuration dialog non-modal. | `Issue #5632 `_ - Ensure that the user will be able to modify the start value of the Identity column. diff --git a/web/pgadmin/misc/file_manager/__init__.py b/web/pgadmin/misc/file_manager/__init__.py index b6dab51bd..89adacf6e 100644 --- a/web/pgadmin/misc/file_manager/__init__.py +++ b/web/pgadmin/misc/file_manager/__init__.py @@ -313,6 +313,9 @@ def save_show_hidden_file_option(trans_id): class Filemanager(object): """FileManager Class.""" + # Stores list of dict for filename & its encoding + loaded_file_encoding_list = [] + def __init__(self, trans_id): self.trans_id = trans_id self.patherror = encode_json( @@ -1088,6 +1091,10 @@ class Filemanager(object): # Check if string is binary is_binary = is_binary_string(file_data) + # Store encoding for future use + Filemanager.loaded_file_encoding_list.\ + append({os.path.basename(filename): enc}) + except IOError as ex: status = False # we don't want to expose real path of file diff --git a/web/pgadmin/tools/sqleditor/__init__.py b/web/pgadmin/tools/sqleditor/__init__.py index 58bb6cde8..ec958ff18 100644 --- a/web/pgadmin/tools/sqleditor/__init__.py +++ b/web/pgadmin/tools/sqleditor/__init__.py @@ -1250,10 +1250,20 @@ def save_file(): file_path.lstrip('/').lstrip('\\') ) + # Get value for encoding if file is already loaded to SQL editor + def get_file_encoding_of_loaded_file(file_name): + encoding = 'utf-8' + for ele in Filemanager.loaded_file_encoding_list: + if file_name in ele: + encoding = ele[file_name] + return encoding + + enc = get_file_encoding_of_loaded_file(os.path.basename(file_path)) + if hasattr(str, 'decode'): file_content = file_data['file_content'] else: - file_content = file_data['file_content'].encode() + file_content = file_data['file_content'].encode(enc) # write to file try: