From 09951ec1cbe5198a7fcfe6c12c5e3c37335b0ede Mon Sep 17 00:00:00 2001 From: Jackson Date: Fri, 27 Aug 2021 19:11:38 -0500 Subject: [PATCH] Moved regex to read file --- src/classes/json_data.py | 5 +++++ src/classes/project_data.py | 16 ---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/src/classes/json_data.py b/src/classes/json_data.py index f71655613b..caf75c0248 100644 --- a/src/classes/json_data.py +++ b/src/classes/json_data.py @@ -153,12 +153,17 @@ def read_from_file(self, file_path, path_mode="ignore"): contents = f.read() if not contents: raise RuntimeError("Couldn't load {} file, no data.".format(self.data_type)) + + if os.path.splitext(file_path) and os.path.splitext(file_path)[1] == '.osp': + # Repair lost quotes on json keys + contents = re.sub('(\n\s*)(\w*):', r'\1"\2":', contents) # Scan for and correct possible OpenShot 2.5.0 corruption if self.damage_re.search(contents) and self.version_re.search(contents): # File contains corruptions, backup and repair self.make_repair_backup(file_path, contents) + # Repair lost slashes, then fix all corrupted escapes contents = self.slash_repair_re.sub(r'\1/\2', contents) contents, subs_count = self.damage_re.subn(r'\\u\1', contents) diff --git a/src/classes/project_data.py b/src/classes/project_data.py index 793c86f8af..0b7157199b 100644 --- a/src/classes/project_data.py +++ b/src/classes/project_data.py @@ -346,7 +346,6 @@ def load(self, file_path, clear_thumbnails=True): default_project = self._data try: - self.quote_json_keys(file_path) # Attempt to load v2.X project file project_data = self.read_from_file(file_path, path_mode="absolute") @@ -721,21 +720,6 @@ def upgrade_project_data_structures(self): if self._data.get("id") == "T0": self._data["id"] = self.generate_id() - # Ensure projects can open - # after PR #4211 introduced a bug - # which wrote certain projects with invalid JSON. - def quote_json_keys(self, file_path): - import re - - f = open(file_path) - txt = f.read() - f.close() - newText = re.sub('(\n\s*)(\w*):', r'\1"\2":', txt) - f = open(file_path, 'w') - f.write(newText) - f.close() - return - def save(self, file_path, move_temp_files=True, make_paths_relative=True): """ Save project file to disk """ import openshot