Skip to content

Commit f75ea5a

Browse files
committed
added in safe target
1 parent 7823e42 commit f75ea5a

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Interlace/lib/core/input.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,16 @@ def _pre_process_commands(command_list, task_name=None, is_global_task=True, sil
113113

114114
@staticmethod
115115
def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
116+
def starts_and_ends_with(string, character):
117+
return string[0] == character and string[-1] == character
116118
TARGET_VAR = "_target_"
117119
HOST_VAR = "_host_"
118120
CLEANTARGET_VAR = "_cleantarget_"
121+
SAFE_TARGET = "_safe-target_"
119122
for task in tasks:
120123
command = task.name()
121-
if TARGET_VAR in command or HOST_VAR in command:
124+
print(command)
125+
if TARGET_VAR in command or HOST_VAR in command or SAFE_TARGET in command:
122126
for dirty_target in itertools.chain(str_targets, ipset_targets):
123127
yielded_task = task.clone()
124128
dirty_target = str(dirty_target)
@@ -129,6 +133,13 @@ def _replace_target_variables_in_commands(tasks, str_targets, ipset_targets):
129133
dirty_target.replace("http://", "").replace(
130134
"https://", "").rstrip("/").replace("/", "-"),
131135
)
136+
137+
if SAFE_TARGET in command:
138+
if (starts_and_ends_with(dirty_target, "'")) or (starts_and_ends_with(dirty_target, '"')):
139+
pass
140+
else:
141+
dirty_target = f"'{dirty_target}'"
142+
yielded_task.replace(SAFE_TARGET, dirty_target)
132143
yield yielded_task
133144
elif CLEANTARGET_VAR in command:
134145
for dirty_target in itertools.chain(str_targets, ipset_targets):

0 commit comments

Comments
 (0)