[MIRROR] Play Internet Sound sanity checks (#5918)

* Play Internet Sound sanity checks (#36080)

* Play Internet Sound sanity checks

Now checks if the content URL uses http(s) before playing

* HTML is not HTTP: renames regex

* Converted global regexes to procs that return them

* Revert "Converted global regexes to procs that return them"

This reverts commit 2eedbd6982b0c4de943a72c94f92f9d75001c06e.

* Play Internet Sound sanity checks
This commit is contained in:
CitadelStationBot
2018-03-12 07:04:43 -05:00
committed by Poojawa
parent 5a4f65a288
commit 4f3115cfbe
5 changed files with 20 additions and 12 deletions
+6 -10
View File
@@ -598,33 +598,29 @@ GLOBAL_LIST_INIT(binary, list("0","1"))
return
//Regular expressions are, as usual, absolute magic
var/regex/is_website = new("http|www.|\[a-z0-9_-]+.(com|org|net|mil|edu)+", "i")
var/regex/is_email = new("\[a-z0-9_-]+@\[a-z0-9_-]+.\[a-z0-9_-]+", "i")
var/regex/alphanumeric = new("\[a-z0-9]+", "i")
var/regex/punctuation = new("\[.!?]+", "i")
var/regex/all_invalid_symbols = new("\[^ -~]+")
var/list/accepted = list()
for(var/string in proposed)
if(findtext(string,is_website) || findtext(string,is_email) || findtext(string,all_invalid_symbols) || !findtext(string,alphanumeric))
if(findtext(string,GLOB.is_website) || findtext(string,GLOB.is_email) || findtext(string,all_invalid_symbols) || !findtext(string,GLOB.is_alphanumeric))
continue
var/buffer = ""
var/early_culling = TRUE
for(var/pos = 1, pos <= lentext(string), pos++)
var/let = copytext(string, pos, (pos + 1) % lentext(string))
if(early_culling && !findtext(let,alphanumeric))
if(early_culling && !findtext(let,GLOB.is_alphanumeric))
continue
early_culling = FALSE
buffer += let
if(!findtext(buffer,alphanumeric))
if(!findtext(buffer,GLOB.is_alphanumeric))
continue
var/punctbuffer = ""
var/cutoff = lentext(buffer)
for(var/pos = lentext(buffer), pos >= 0, pos--)
var/let = copytext(buffer, pos, (pos + 1) % lentext(buffer))
if(findtext(let,alphanumeric))
if(findtext(let,GLOB.is_alphanumeric))
break
if(findtext(let,punctuation))
if(findtext(let,GLOB.is_punctuation))
punctbuffer = let + punctbuffer //Note this isn't the same thing as using +=
cutoff = pos
if(punctbuffer) //We clip down excessive punctuation to get the letter count lower and reduce repeats. It's not perfect but it helps.
@@ -652,7 +648,7 @@ GLOBAL_LIST_INIT(binary, list("0","1"))
else
punctbuffer = "" //Grammer nazis be damned
buffer = copytext(buffer, 1, cutoff) + punctbuffer
if(!findtext(buffer,alphanumeric))
if(!findtext(buffer,GLOB.is_alphanumeric))
continue
if(!buffer || lentext(buffer) > 280 || lentext(buffer) <= cullshort || buffer in accepted)
continue