Branch was auto-updated.

This commit is contained in:
srv-rr-gh-researchbt
2023-07-11 13:03:02 -07:00
committed by GitHub
@@ -6,6 +6,7 @@ from pydantic import BaseModel, validator, root_validator
from dataclasses import dataclass
from datetime import datetime
from typing import Union
import re
from bin.contentctl_project.contentctl_core.domain.entities.security_content_object import (
@@ -139,6 +140,23 @@ class Detection(BaseModel, SecurityContentObject):
raise ValueError("name is longer then 67 chars: " + values["name"])
return values
@root_validator
def new_line_check(cls, values):
# Check if there is a new line in description and how to implement that is not escaped
pattern = r'(?<!\\)\n'
if re.search(pattern, values["description"]):
match_obj = re.search(pattern,values["description"])
words = values["description"][:match_obj.span()[0]].split()[-10:]
newline_context = ' '.join(words)
raise ValueError(f"Field named 'description' contains new line that is not escaped using backslash. Add backslash at the end of the line after the words: '{newline_context}' in '{values['name']}'")
if re.search(pattern, values["how_to_implement"]):
match_obj = re.search(pattern,values["how_to_implement"])
words = values["how_to_implement"][:match_obj.span()[0]].split()[-10:]
newline_context = ' '.join(words)
raise ValueError(f"Field named 'how_to_implement' contains new line that is not escaped using backslash. Add backslash at the end of the line after the words: '{newline_context}' in '{values['name']}'")
return values
# @validator('references')
# def references_check(cls, v, values):
# return LinkValidator.SecurityContentObject_validate_references(v, values)