Repository: coreruleset/coreruleset

Issue:
Regex assembler seems to be broken again.
### Describe the bug
`util/regexp-assemble/regexp-assemble.py --log-level DEBUG update 942521`

```
Processing 942521, chain offset 0
detected processor: <class 'NoneType'>
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found simple comment
Found regular input '##!^ ^\n'
Found regular input '##!+ i\n'
Found simple comment
Found simple comment
Found regular input "[^']*?(?:'[^']*?'[^']*?)*?'\\s*(\\w+)\\b\n"
Found regular input '[^\\"]*?(?:\\"[^\\"]*?\\"[^\\"]*?)*?\\"\\s*(\\w+)\\b\n'
Found regular input '[^`]*?(?:`[^`]*?`[^`]*?)*?`\\s*(\\w+)\\b\n'
processor will process: ['##!^ ^\n', '##!+ i\n', "[^']*?(?:'[^']*?'[^']*?)*?'\\s*(\\w+)\\b\n", '[^\\"]*?(?:\\"[^\\"]*?\\"[^\\"]*?)*?\\"\\s*(\\w+)\\b\n', '[^`]*?(?:`[^`]*?`[^`]*?)*?`\\s*(\\w+)\\b\n']
preprocessed lines: ['##!^ ^\n', '##!+ i\n', "[^']*?(?:'[^']*?'[^']*?)*?'\\s*(\\w+)\\b\n", '[^\\"]*?(?:\\"[^\\"]*?\\"[^\\"]*?)*?\\"\\s*(\\w+)\\b\n', '[^`]*?(?:`[^`]*?`[^`]*?)*?`\\s*(\\w+)\\b\n']
Completing assembly
Running assembler with lines: ['##!^ ^', '##!+ i', "[^']*?(?:'[^']*?'[^']*?)*?'\\s*(\\w+)\\b", '[^\\"]*?(?:\\"[^\\"]*?\\"[^\\"]*?)*?\\"\\s*(\\w+)\\b', '[^`]*?(?:`[^`]*?`[^`]*?)*?`\\s*(\\w+)\\b']
Assembler errors: b'', output b'(?i)^(?:[^\\"]*?(?:\\"[^\\"]*?\\"[^\\"]*?)*?\\"|[^\']*?(?:\'[^\']*?\'[^\']*?)*?\'|[^`]*?(?:`[^`]*?`[^`]*?)*?`)\\s*(\\w+)\\b\n'
Completed assembly: (?i)^(?:[^\"]*?(?:\"[^\"]*?\"[^\"]*?)*?\"|[^']*?(?:'[^']*?'[^']*?)*?'|[^`]*?(?:`[^`]*?`[^`]*?)*?`)\s*(\w+)\b
Traceback (most recent call last):
  File "util/regexp-assemble/regexp-assemble.py", line 227, in <module>
    namespace.func(namespace)
  File "util/regexp-assemble/regexp-assemble.py", line 146, in handle_update
    updater.run(False)
  File "/home/janek/crs-waf/coreruleset/util/regexp-assemble/lib/operators/updater.py", line 8, in run
    self.write_updates()
  File "/home/janek/crs-waf/coreruleset/util/regexp-assemble/lib/operators/updater.py", line 24, in write_updates
    with open(file_path, "w") as handle:
FileNotFoundError: [Errno 2] No such file or directory: 'rules/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf'
```

It seems that there is double `rules/rules` so updating a rule doesn't work. 

@theseion 


Discussion:
Thanks for reporting @terjanq. I see where there might be an issue in the code but I can't recreate your stack trace. Which version of Python are you using and on which commit have you tested this?
I tested on my branch https://github.com/terjanq/coreruleset/tree/patch-new-crazy-rule-942520 
I could have resolved some of my conflicts incorrectly. 

Python version: `Python 3.8.12`

Resolving patch:
diff --git a/util/regexp-assemble/lib/operators/updater.py b/util/regexp-assemble/lib/operators/updater.py
--- a/util/regexp-assemble/lib/operators/updater.py
+++ b/util/regexp-assemble/lib/operators/updater.py
@@ -20,8 +20,7 @@ def update_regex(
     def write_updates(self):
         for rule_prefix, parser in self.parsers.items():
             writer = MSCWriter(parser.configlines)
-            file_path = self.context.rules_directory / self.prefix_to_file_map[rule_prefix]
-            with open(file_path, "w") as handle:
+            with self.prefix_to_file_map[rule_prefix].open("w") as handle:
                 writer.generate()
                 # add extra new line at the end of file
                 writer.output.append("")


Test patch: