10
10
from contentctl .input .director import DirectorOutputDto
11
11
from contentctl .objects .security_content_object import SecurityContentObject
12
12
13
-
14
13
#The following macros are included in commonly-installed apps.
15
14
#As such, we will ignore if they are missing from our app.
16
15
#Included in
@@ -55,10 +54,15 @@ def get_macros(text_field:str, director:DirectorOutputDto , ignore_macros:set[st
55
54
#If a comment ENDS in a macro, for example ```this is a comment with a macro `macro_here````
56
55
#then there is a small edge case where the regex below does not work properly. If that is
57
56
#the case, we edit the search slightly to insert a space
58
- text_field = re .sub (r"\`\`\`\`" , r"` ```" , text_field )
59
- text_field = re .sub (r"\`\`\`.*?\`\`\`" , " " , text_field )
60
-
57
+ if re .findall (r"\`\`\`\`" , text_field ):
58
+ raise ValueError ("Search contained four or more '`' characters in a row which is invalid SPL"
59
+ "This may have occurred when a macro was commented out.\n "
60
+ "Please ammend your search to remove the substring '````'" )
61
61
62
+ # replace all the macros with a space
63
+ text_field = re .sub (r"\`\`\`[\s\S]*?\`\`\`" , " " , text_field )
64
+
65
+
62
66
macros_to_get = re .findall (r'`([^\s]+)`' , text_field )
63
67
#If macros take arguments, stop at the first argument. We just want the name of the macro
64
68
macros_to_get = set ([macro [:macro .find ('(' )] if macro .find ('(' ) != - 1 else macro for macro in macros_to_get ])
@@ -68,4 +72,3 @@ def get_macros(text_field:str, director:DirectorOutputDto , ignore_macros:set[st
68
72
macros_to_get -= macros_to_ignore
69
73
return Macro .mapNamesToSecurityContentObjects (list (macros_to_get ), director )
70
74
71
-
0 commit comments