Use regex to check forbidden terms. (#5784)

We were returning and `Elementul` as a match for the forbidden term `Element`. It now checks for the full word.
This commit is contained in:
Jorge Martin Espinosa
2025-11-21 17:01:01 +01:00
committed by GitHub
parent efc4896118
commit e428e10ed6

View File

@@ -6,6 +6,7 @@
# SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
# Please see LICENSE files in the repository root for full details.
import re
import sys
from xml.dom import minidom
@@ -14,7 +15,7 @@ file = sys.argv[1]
# Dict of forbidden terms, with exceptions for some String name
# Keys are the terms, values are the exceptions.
forbiddenTerms = {
"Element": [
r"\bElement\b": [
# Those 2 strings are only used in debug version
"screen_advanced_settings_element_call_base_url",
"screen_advanced_settings_element_call_base_url_description",
@@ -48,7 +49,8 @@ for elem in content.getElementsByTagName('string'):
value = child.nodeValue
# If value contains a forbidden term, add the error to errors
for (term, exceptions) in forbiddenTerms.items():
if term in value and name not in exceptions:
matches = re.search(term, value)
if matches and name not in exceptions:
errors.append('Forbidden term "' + term + '" in string: "' + name + '": ' + value)
### Plurals
@@ -65,7 +67,8 @@ for elem in content.getElementsByTagName('plurals'):
value = child.nodeValue
# If value contains a forbidden term, add the error to errors
for (term, exceptions) in forbiddenTerms.items():
if term in value and name not in exceptions:
matches = re.search(term, value)
if matches and name not in exceptions:
errors.append('Forbidden term "' + term + '" in plural: "' + name + '": ' + value)
# If errors is not empty print the report