Skip to content

Commit bca05a6

Browse files
committed
update regex to search method so it would work with complements
1 parent 464a0da commit bca05a6

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/scrapy_settings_log/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def spider_closed(self, spider):
5858
]
5959
regex_list = settings.get("MASKED_SENSITIVE_SETTINGS_REGEX_LIST", default_regexes)
6060
for reg in regex_list:
61-
updated_settings = {k: '*'*len(v) for k, v in settings.items() if re.match(reg, k)}
61+
updated_settings = {k: '*'*len(v) for k, v in settings.items() if re.search(reg, k)}
6262
settings = {**settings, **updated_settings}
6363

6464
self.output_settings(settings, spider)

tests/test_code.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ class CustomClass:
108108
def test_log_all_should_not_return_apikey_value_by_default(caplog):
109109
settings = {
110110
"SETTINGS_LOGGING_ENABLED": True,
111-
"APIKEY": 'apikey_value1',
112-
"apikey": 'apikey_value2',
111+
"SHUB_APIKEY": 'apikey_value1',
112+
"shub_apikey": 'apikey_value2',
113113
"api_key": 'apikey_value3',
114114
}
115115

@@ -118,8 +118,8 @@ def test_log_all_should_not_return_apikey_value_by_default(caplog):
118118
with caplog.at_level(logging.INFO):
119119
logger.spider_closed(spider)
120120

121-
assert '"APIKEY": "*************"' in caplog.text
122-
assert '"apikey": "*************"' in caplog.text
121+
assert '"SHUB_APIKEY": "*************"' in caplog.text
122+
assert '"shub_apikey": "*************"' in caplog.text
123123
assert '"api_key": "*************"' in caplog.text
124124
assert 'apikey_value' not in caplog.text
125125

0 commit comments

Comments
 (0)