Skip to content

Commit

Permalink
Moved regex to read file
Browse files Browse the repository at this point in the history
  • Loading branch information
Jackson committed Aug 28, 2021
1 parent 4238b0a commit 09951ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/classes/json_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 0 additions & 16 deletions src/classes/project_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 09951ec

Please sign in to comment.