Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f46e522

Browse filesBrowse files
authored
Fixes some potential fatal errors in how paper handles language scrambling (yogstation13#7723)
* Fixes some potential fatal errors in /proc/scramble_HTML * Massively simplifies the regex for scramble_HTML Apparently this ought to be safe, since the plaintext inside has already been through html_encode() in some way, hopefully. * plantext.group -> plaintext.group * Fixes bug in new regex in scramble_HTML()
1 parent f5ee3f4 commit f46e522
Copy full SHA for f46e522

1 file changed

+6-5Lines changed: 6 additions & 5 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎code/modules/language/language.dm‎

Copy file name to clipboardExpand all lines: code/modules/language/language.dm
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,17 @@
111111

112112
/datum/language/proc/scramble_HTML(intext) // Calls scramble() on HTML text, making sure to not disturb the HTML.
113113
var/text = ""
114-
var/regex/plaintext = regex(@"(?:<\/?[\w\s\d=\x22]+>|^)((?:[\w\s\d!@#$%^&*\(\)\-+?:\x22'}{\[\]~`|;,.\\])+)") // Finds plaintext within the HTML.
114+
var/regex/plaintext = regex(@"((>|^)([^<>]+)(?:<|$)") // Finds plaintext within the HTML.
115115
var/newtext = intext
116116
var/startpos = 1
117117
while(startpos < 8192 && startpos > -1)
118-
var/f = plaintext.Find(newtext,startpos)
119-
if(!f)
118+
var/regexstart = plaintext.Find(newtext,startpos) // Where the *regex* first matches
119+
if(!regexstart)
120120
break
121-
var/sentence = plaintext.group[1]
121+
var/capturestart = regexstart + length(plaintext.group[1]) // Where the *capture* first matches, the actual plaintext of this section
122+
var/sentence = plaintext.group[2]
122123
var/scramb = scramble(sentence) // The scrambled version of the sentence.
123-
newtext = replacetext(newtext, sentence, scramb, f, length(sentence)+1)
124+
newtext = replacetext(newtext, sentence, scramb, capturestart, capturestart + length(sentence)+1)
124125
startpos = plaintext.next + (length(scramb) - length(sentence))
125126
text += newtext
126127
return text

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.