adjustments for items in [ ].

bug: value with same name of an attribute was considered an attribute.
This commit is contained in:
2024-06-22 23:30:07 -03:00
parent 0dc05b9c4d
commit 54d1892374
2 changed files with 20 additions and 11 deletions

View File

@@ -27,11 +27,12 @@ import re
class Redaction():
def repl_value(self, message, pattern, r):
def repl_value(self, message, pattern):
flag_aspas = False
flag_attribute = False
# flag_vezes = 0
flag_dois_pontos = False
flag_colchetes = False
i = 0
z = pattern
str_acc = ""
@@ -51,14 +52,24 @@ class Redaction():
flag_attribute = False
flag_dois_pontos = False
flag_aspas = False
if ((message[i] == "}" or message[i] == "]" or message[i] == ",") and flag_dois_pontos and not flag_aspas and flag_attribute):
flag_colchetes = False
if ((message[i] == "}" or message[i] == "]") and not flag_aspas):
flag_attribute = False
flag_dois_pontos = False
flag_aspas = False
flag_colchetes = False
str_acc = ""
if (flag_dois_pontos and not flag_aspas and message[i] == "["):
flag_colchetes = True
if (message[i] == "," and not flag_aspas and not flag_colchetes):
flag_attribute = False
flag_dois_pontos = False
flag_aspas = False
flag_colchetes = False
str_acc = ""
if ((message[i] == "'" or message[i] == "\"")):
flag_aspas = not flag_aspas
if (flag_aspas == False and flag_attribute == True and flag_dois_pontos and len(str_acc) > 0):
if (flag_aspas == False and flag_attribute == True and flag_dois_pontos and len(str_acc) > 0 and not flag_colchetes):
flag_attribute = False
flag_dois_pontos = False
str_acc = ""
@@ -68,12 +79,7 @@ class Redaction():
def repl(self, attribute_pattern, message):
msg_return = []
for pattern in attribute_pattern:
x = re.finditer(pattern, message)
for y in x:
msg_aux1 = []
for reg in y.regs:
for r in reg:
message = self.repl_value(message, pattern, r)
message = self.repl_value(message, pattern)
return message
def change(self, sensitive_pattern, message):

View File

@@ -11,6 +11,7 @@ SENSITIVE_PATTERNS = [
ATTRIBUTE_PATTERNS = [
"nome",
"$ref",
"cpf",
"teste",
"valor",
@@ -21,7 +22,8 @@ ATTRIBUTE_PATTERNS = [
"chave",
"description",
"items",
"example"
"example",
"required"
]
Messages = [
@@ -34,7 +36,8 @@ Messages = [
"User's phone number: (123) 456-7890",
"User's date of birth: 04/29/1990",
"User's IP address: 192.168.1.1",
"User's API key: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6"
"User's API key: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6",
'{ "nome": "João Silva", "cpf": "123.456.789-00", "teste": "Teste Valor", "valor": 200.00, "original": "Original Valor", "type": "Tipo Valor", "solicitacaoPagador": "Solicitação Pagador", "expiracao": "2021-12-31", "chave": "Chave Valor", "description": "Descrição Valor", "items": ["Item1", "Item2"], "example": "Exemplo Valor"}'
]
redaction = Redaction.Redaction()