Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Плохие слово харам/запретить #36

Merged
merged 4 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion code/__DEFINES/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define SANITIZE_FILENAME(text) (GLOB.filename_forbidden_chars.Replace(text, ""))

/// Simply removes the < and > characters, and limits the length of the message.
#define STRIP_HTML_SIMPLE(text, limit) (GLOB.angular_brackets.Replace(copytext(text, 1, limit), ""))
#define STRIP_HTML_SIMPLE(text, limit) (GLOB.angular_brackets.Replace_char(copytext_char(text, 1, limit), "")) //MASSMETA EDIT

/// Removes everything enclose in < and > inclusive of the bracket, and limits the length of the message.
#define STRIP_HTML_FULL(text, limit) (GLOB.html_tags.Replace(copytext(text, 1, limit), ""))
Expand Down
12 changes: 6 additions & 6 deletions code/__HELPERS/chat_filter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// Given a text, will return what word is on the IC filter, with the reason.
/// Returns null if the message is OK.
/proc/is_ic_filtered(message)
if (config.ic_filter_regex?.Find(message))
if (config.ic_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.ic_filter_regex)
return list(
matched_group,
Expand All @@ -17,7 +17,7 @@
/// Given a text, will return what word is on the soft IC filter, with the reason.
/// Returns null if the message is OK.
/proc/is_soft_ic_filtered(message)
if (config.soft_ic_filter_regex?.Find(message))
if (config.soft_ic_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.soft_ic_filter_regex)
return list(
matched_group,
Expand All @@ -29,7 +29,7 @@
/// Given a text, will return what word is on the OOC filter, with the reason.
/// Returns null if the message is OK.
/proc/is_ooc_filtered(message)
if (config.ooc_filter_regex?.Find(message))
if (config.ooc_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.ooc_filter_regex)
return list(matched_group, config.shared_filter_reasons[matched_group])

Expand All @@ -38,7 +38,7 @@
/// Given a text, will return that word is on the soft OOC filter, with the reason.
/// Returns null if the message is OK.
/proc/is_soft_ooc_filtered(message)
if (config.soft_ooc_filter_regex?.Find(message))
if (config.soft_ooc_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.soft_ooc_filter_regex)
return list(matched_group, config.soft_shared_filter_reasons[matched_group])

Expand All @@ -64,7 +64,7 @@
/// Given a text, will return what word is on the IC filter, ignoring words allowed on the PDA, with the reason.
/// Returns null if the message is OK.
/proc/is_ic_filtered_for_pdas(message)
if (config.ic_outside_pda_filter_regex?.Find(message))
if (config.ic_outside_pda_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.ic_outside_pda_filter_regex)
return list(
matched_group,
Expand All @@ -76,7 +76,7 @@
/// Given a text, will return what word is on the soft IC filter, ignoring words allowed on the PDA, with the reason.
/// Returns null if the message is OK.
/proc/is_soft_ic_filtered_for_pdas(message)
if (config.soft_ic_outside_pda_filter_regex?.Find(message))
if (config.soft_ic_outside_pda_filter_regex?.Find_char(lowertext(message))) //MASSMETA EDIT
var/matched_group = GET_MATCHED_GROUP(config.soft_ic_outside_pda_filter_regex)
return list(
matched_group,
Expand Down
28 changes: 14 additions & 14 deletions code/__HELPERS/text.dm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/// Runs byond's html encoding sanitization proc, after replacing new-lines and tabs for the # character.
/proc/sanitize(text)
var/static/regex/regex = regex(@"[\n\t]", "g")
return html_encode(regex.Replace(text, "#"))
return html_encode(regex.Replace_char(text, "#")) //MASSMETA EDIT


/// Runs STRIP_HTML_SIMPLE and sanitize.
Expand Down Expand Up @@ -66,14 +66,14 @@
*/
/proc/htmlrendertext(t)
// Trim "whitespace" by lazily capturing word characters in the middle
var/static/regex/matchMiddle = new(@"^\s*([\W\w]*?)\s*$")
if(matchMiddle.Find(t) == 0)
var/static/regex/matchMiddle = new(@"^\s*([\W\wа-яё]*?)\s*$", "i") //MASSMETA EDIT
if(matchMiddle.Find_char(t) == 0) //MASSMETA EDIT
return t
t = matchMiddle.group[1]

// Replace any non-space whitespace characters with spaces, and also multiple occurences with just one space
var/static/regex/matchSpacing = new(@"\s+", "g")
t = replacetext(t, matchSpacing, " ")
t = replacetext_char(t, matchSpacing, " ") //MASSMETA EDIT

return t

Expand Down Expand Up @@ -121,7 +121,7 @@
if(isnull(user_input)) // User pressed cancel
return
if(no_trim)
return copytext(html_encode(user_input), 1, max_length)
return copytext_char(html_encode(user_input), 1, max_length) //MASSMETA EDIT
else
return trim(html_encode(user_input), max_length) //trim is "outside" because html_encode can expand single symbols into multiple symbols (such as turning < into &lt;)

Expand Down Expand Up @@ -297,16 +297,16 @@

//Returns a string with reserved characters and spaces before the first letter removed
/proc/trim_left(text)
for (var/i = 1 to length(text))
if (text2ascii(text, i) > 32)
return copytext(text, i)
for (var/i = 1 to length_char(text)) //MASSMETA EDIT
if (text2ascii_char(text, i) > 32) //MASSMETA EDIT
return copytext_char(text, i) //MASSMETA EDIT
return ""

//Returns a string with reserved characters and spaces after the last letter removed
/proc/trim_right(text)
for (var/i = length(text), i > 0, i--)
if (text2ascii(text, i) > 32)
return copytext(text, 1, i + 1)
for (var/i = length_char(text), i > 0, i--) //MASSMETA EDIT
if (text2ascii_char(text, i) > 32) //MASSMETA EDIT
return copytext_char(text, 1, i + 1) //MASSMETA EDIT
return ""

//Returns a string with reserved characters and spaces after the first and last letters removed
Expand Down Expand Up @@ -339,8 +339,8 @@
* * max_length - integer length to truncate at
*/
/proc/truncate(text, max_length)
if(length(text) > max_length)
return copytext(text, 1, max_length)
if(length_char(text) > max_length) //MASSMETA EDIT
return copytext_char(text, 1, max_length) //MASSMETA EDIT
return text

//Returns a string with reserved characters and spaces before the first word and after the last word removed.
Expand All @@ -354,7 +354,7 @@
. = t
if(t)
. = t[1]
return uppertext(.) + copytext(t, 1 + length(.))
return uppertext(.) + copytext_char(t, 1 + length_char(.)) //MASSMETA EDIT

///Returns a string with the first letter of each word capitialized
/proc/full_capitalize(input)
Expand Down
4 changes: 2 additions & 2 deletions code/controllers/configuration/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ Example config:
if (isnull(banned_words) || banned_words.len == 0)
return null

var/static/regex/should_join_on_word_bounds = regex(@"^\w+$")
var/static/regex/should_join_on_word_bounds = regex(@"^[\wа-яё]+$", "i") //MASSMETA EDIT

// Stuff like emoticons needs another split, since there's no way to get ":)" on a word bound.
// Furthermore, normal words need to be on word bounds, so "(adminhelp)" gets filtered.
Expand All @@ -493,7 +493,7 @@ Example config:

// We don't want a whitespace_split part if there's no stuff that requires it
var/whitespace_split = to_join_on_whitespace_splits.len > 0 ? @"(?:(?:^|\s+)(" + jointext(to_join_on_whitespace_splits, "|") + @")(?:$|\s+))" : ""
var/word_bounds = @"(\b(" + jointext(to_join_on_word_bounds, "|") + @")\b)"
var/word_bounds = @"((" + jointext(to_join_on_word_bounds, "|") + @"))" //MASSMETA EDIT
var/regex_filter = whitespace_split != "" ? "([whitespace_split]|[word_bounds])" : word_bounds
return regex(regex_filter, "i")

Expand Down
6 changes: 6 additions & 0 deletions code/modules/unit_tests/chat_filter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
null,
)

//MASSMETA EDIT REMOVAL BEGIN - CODE_WORDS - these words HAVE filtered words in them
/*

test_filter(
"these words have filtered words in them: ablockedinic blockedinicbbbb aablockedinicbb",
null,
Expand All @@ -34,6 +37,9 @@
null,
)

*/
//MASSMETA EDIT REMOVAL END

test_filter(
"<(0_0<) <(0_0)> (>0_0)> KIRBY DANCE!!!",
"<(0_0<)",
Expand Down
Loading