summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSamuel Bartík <[email protected]>2022-07-06 18:57:19 +0200
committerGitHub <[email protected]>2022-07-06 12:57:19 -0400
commit741a8172b2cb8f1a1698750eab96b640dc989d9b (patch)
tree855739f68ee25d700040b819feb24bcfbad72926
parent5c1399e9f281a67aa9905adf9d998171f66a20fd (diff)
downloadbazarr-741a8172b2cb8f1a1698750eab96b640dc989d9b.tar.gz
bazarr-741a8172b2cb8f1a1698750eab96b640dc989d9b.zip
Fixed quotation marks escaping in post-processing variables (#1882)
-rw-r--r--bazarr/utilities/post_processing.py40
1 files changed, 23 insertions, 17 deletions
diff --git a/bazarr/utilities/post_processing.py b/bazarr/utilities/post_processing.py
index 5ac56ba2d..7a126e9cd 100644
--- a/bazarr/utilities/post_processing.py
+++ b/bazarr/utilities/post_processing.py
@@ -1,24 +1,30 @@
# coding=utf-8
import os
+import re
+# Wraps the input string within quotes & escapes the string
+def _escape(in_str):
+ raw_map = {8:r'\b', 7:r'\a', 12:r'\f', 10:r'\n', 13:r'\r', 9:r'\t', 11:r'\v', 39:'\\\'', 34:'"', 92:'\\'}
+ raw_str = r''.join(raw_map.get(ord(i), i) for i in in_str)
+ return f"'{raw_str}'"
def pp_replace(pp_command, episode, subtitles, language, language_code2, language_code3, episode_language, episode_language_code2, episode_language_code3, forced, score, subtitle_id, provider, series_id, episode_id, hi):
- pp_command = pp_command.replace('{{directory}}', os.path.dirname(episode))
- pp_command = pp_command.replace('{{episode}}', episode)
- pp_command = pp_command.replace('{{episode_name}}', os.path.splitext(os.path.basename(episode))[0])
- pp_command = pp_command.replace('{{subtitles}}', str(subtitles))
- pp_command = pp_command.replace('{{subtitles_language}}', str(language))
- pp_command = pp_command.replace('{{subtitles_language_code2}}', str(language_code2))
- pp_command = pp_command.replace('{{subtitles_language_code3}}', str(language_code3))
- pp_command = pp_command.replace('{{subtitles_language_code2_dot}}', str(language_code2).replace(':', '.'))
- pp_command = pp_command.replace('{{subtitles_language_code3_dot}}', str(language_code3).replace(':', '.'))
- pp_command = pp_command.replace('{{episode_language}}', str(episode_language))
- pp_command = pp_command.replace('{{episode_language_code2}}', str(episode_language_code2))
- pp_command = pp_command.replace('{{episode_language_code3}}', str(episode_language_code3))
- pp_command = pp_command.replace('{{score}}', str(score))
- pp_command = pp_command.replace('{{subtitle_id}}', str(subtitle_id))
- pp_command = pp_command.replace('{{provider}}', str(provider))
- pp_command = pp_command.replace('{{series_id}}', str(series_id))
- pp_command = pp_command.replace('{{episode_id}}', str(episode_id))
+ pp_command = re.sub(r'[\'"]?{{directory}}[\'"]?', _escape(os.path.dirname(episode)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode}}[\'"]?', _escape(episode), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode_name}}[\'"]?', _escape(os.path.splitext(os.path.basename(episode))[0]), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles}}[\'"]?', _escape(str(subtitles)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles_language}}[\'"]?', _escape(str(language)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles_language_code2}}[\'"]?', _escape(str(language_code2)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles_language_code3}}[\'"]?', _escape(str(language_code3)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles_language_code2_dot}}[\'"]?', _escape(str(language_code2).replace(':', '.')), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitles_language_code3_dot}}[\'"]?', _escape(str(language_code3).replace(':', '.')), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode_language}}[\'"]?', _escape(str(episode_language)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode_language_code2}}[\'"]?', _escape(str(episode_language_code2)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode_language_code3}}[\'"]?', _escape(str(episode_language_code3)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{score}}[\'"]?', _escape(str(score)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{subtitle_id}}[\'"]?', _escape(str(subtitle_id)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{provider}}[\'"]?', _escape(str(provider)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{series_id}}[\'"]?', _escape(str(series_id)), pp_command)
+ pp_command = re.sub(r'[\'"]?{{episode_id}}[\'"]?', _escape(str(episode_id)), pp_command)
return pp_command