From bbb1b82c5b5bc9c7e9cd96c41aa8339a95e49864 Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Tue, 23 Feb 2021 19:21:43 -0800 Subject: added fix for special characters in board name, also escaped some characters for regex. might be some missing edge cases --- client.go | 2 +- main.go | 12 ++++++++++-- static/js/posts.js | 13 +++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/client.go b/client.go index f11caae..d31ba07 100644 --- a/client.go +++ b/client.go @@ -210,7 +210,7 @@ func PostGet(w http.ResponseWriter, r *http.Request, db *sql.DB){ returnData.Boards = Boards - re = regexp.MustCompile("f\\w+-\\w+") + re = regexp.MustCompile("f(\\w|[!@#$%^&*<>])+-(\\w|[!@#$%^&*<>])+") if re.MatchString(path) { // if non local actor post name := GetActorFollowNameFromPath(path) diff --git a/main.go b/main.go index 58e8f3d..6383aaf 100644 --- a/main.go +++ b/main.go @@ -118,11 +118,19 @@ func main() { actorReported = (path == "/" + actor.Name + "/reported") actorVerification = (path == "/" + actor.Name + "/verification") - re := regexp.MustCompile("/" + actor.Name + "/[0-9]{1,2}$") + escapedActorName := strings.Replace(actor.Name, "*", "\\*", -1) + escapedActorName = strings.Replace(escapedActorName, "^", "\\^", -1) + escapedActorName = strings.Replace(escapedActorName, "$", "\\$", -1) + escapedActorName = strings.Replace(escapedActorName, "?", "\\?", -1) + escapedActorName = strings.Replace(escapedActorName, "+", "\\+", -1) + escapedActorName = strings.Replace(escapedActorName, ".", "\\.", -1) + + re := regexp.MustCompile("/" + escapedActorName + "/[0-9]{1,2}$") actorMainPage = re.MatchString(path) - re = regexp.MustCompile("/" + actor.Name + "/\\w+") + re = regexp.MustCompile("/" + escapedActorName + "/\\w+") + actorPost = re.MatchString(path) } diff --git a/static/js/posts.js b/static/js/posts.js index 1cb032e..d6395e2 100644 --- a/static/js/posts.js +++ b/static/js/posts.js @@ -24,10 +24,9 @@ function getMIMEType(type) function shortURL(actorName, url) { - var check = url.replace(actorName + "/", "") re = /.+\//g; temp = re.exec(url) - + if(stripTransferProtocol(temp[0]) == stripTransferProtocol(actorName) + "/") { var short = url.replace("https://", ""); @@ -57,11 +56,13 @@ function shortURL(actorName, url) u = re.exec(short); + str = short.replace(/\/+/g, " ") + + str = str.replace(u, " ").trim() - replace = short.replace(/\/+/g, " ") - replace = replace.replace(u, " ").trim() - re = /\w+$/; - v = re.exec(replace) + re = /(\w|[!@#$%^&*<>])+$/; + + v = re.exec(str) v = "f" + v[0] + "-" + u -- cgit v1.2.3