From c57bc6a39bcc15da13a5833874653b2d2f9ac702 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Tue, 24 Jul 2018 12:30:45 +0530 Subject: [PATCH] api: standardise strip fn names --- api/comment_list.go | 2 +- api/comment_new.go | 2 +- api/domain_delete.go | 2 +- api/domain_import_disqus.go | 4 ++-- api/domain_moderator_delete.go | 2 +- api/domain_moderator_new.go | 2 +- api/domain_new.go | 2 +- api/domain_statistics.go | 2 +- api/domain_update.go | 2 +- api/utils_sanitise.go | 6 +++--- api/utils_sanitise_test.go | 6 +++--- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/api/comment_list.go b/api/comment_list.go index ab0c21d..173dfd3 100644 --- a/api/comment_list.go +++ b/api/comment_list.go @@ -102,7 +102,7 @@ func commentListHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) path := *x.Path d, err := domainGet(domain) diff --git a/api/comment_new.go b/api/comment_new.go index dd14607..15f8e7b 100644 --- a/api/comment_new.go +++ b/api/comment_new.go @@ -49,7 +49,7 @@ func commentNewHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) path := *x.Path d, err := domainGet(domain) diff --git a/api/domain_delete.go b/api/domain_delete.go index 998ac0f..5b68534 100644 --- a/api/domain_delete.go +++ b/api/domain_delete.go @@ -81,7 +81,7 @@ func domainDeleteHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) isOwner, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_import_disqus.go b/api/domain_import_disqus.go index 1116414..a6eb544 100644 --- a/api/domain_import_disqus.go +++ b/api/domain_import_disqus.go @@ -150,7 +150,7 @@ func domainImportDisqus(domain string, url string) (int, error) { commentHex, err := commentNew( commenterHex[post.Author.Email], domain, - stripPath(threads[post.ThreadId.Id].URL), + pathStrip(threads[post.ThreadId.Id].URL), parentHex, html2md.Convert(post.Message), "approved", @@ -185,7 +185,7 @@ func domainImportDisqusHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) isOwner, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_moderator_delete.go b/api/domain_moderator_delete.go index 5c4dd1a..8b1986c 100644 --- a/api/domain_moderator_delete.go +++ b/api/domain_moderator_delete.go @@ -41,7 +41,7 @@ func domainModeratorDeleteHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) authorised, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_moderator_new.go b/api/domain_moderator_new.go index b226e00..3ec52d4 100644 --- a/api/domain_moderator_new.go +++ b/api/domain_moderator_new.go @@ -43,7 +43,7 @@ func domainModeratorNewHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) isOwner, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_new.go b/api/domain_new.go index 43f923a..7dbba13 100644 --- a/api/domain_new.go +++ b/api/domain_new.go @@ -43,7 +43,7 @@ func domainNewHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) if err = domainNew(o.OwnerHex, *x.Name, domain); err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_statistics.go b/api/domain_statistics.go index 979ab26..b14ceab 100644 --- a/api/domain_statistics.go +++ b/api/domain_statistics.go @@ -55,7 +55,7 @@ func domainStatisticsHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain(*x.Domain) + domain := domainStrip(*x.Domain) isOwner, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/domain_update.go b/api/domain_update.go index 630be7b..4b4ac9c 100644 --- a/api/domain_update.go +++ b/api/domain_update.go @@ -38,7 +38,7 @@ func domainUpdateHandler(w http.ResponseWriter, r *http.Request) { return } - domain := stripDomain((*x.D).Domain) + domain := domainStrip((*x.D).Domain) isOwner, err := domainOwnershipVerify(o.OwnerHex, domain) if err != nil { bodyMarshal(w, response{"success": false, "message": err.Error()}) diff --git a/api/utils_sanitise.go b/api/utils_sanitise.go index 89adaaa..087b274 100644 --- a/api/utils_sanitise.go +++ b/api/utils_sanitise.go @@ -8,7 +8,7 @@ var prePlusMatch = regexp.MustCompile(`([^@\+]*)\+?(.*)@.*`) var periodsMatch = regexp.MustCompile(`[\.]`) var postAtMatch = regexp.MustCompile(`[^@]*(@.*)`) -func stripEmail(email string) string { +func emailStrip(email string) string { postAt := postAtMatch.ReplaceAllString(email, `$1`) prePlus := prePlusMatch.ReplaceAllString(email, `$1`) strippedEmail := periodsMatch.ReplaceAllString(prePlus, ``) + postAt @@ -19,7 +19,7 @@ func stripEmail(email string) string { var https = regexp.MustCompile(`(https?://)`) var trailingSlash = regexp.MustCompile(`(/*$)`) -func stripDomain(domain string) string { +func domainStrip(domain string) string { noSlash := trailingSlash.ReplaceAllString(domain, ``) noProtocol := https.ReplaceAllString(noSlash, ``) @@ -28,7 +28,7 @@ func stripDomain(domain string) string { var pathMatch = regexp.MustCompile(`(https?://[^/]*)`) -func stripPath(url string) string { +func pathStrip(url string) string { strippedPath := pathMatch.ReplaceAllString(url, ``) return strippedPath diff --git a/api/utils_sanitise_test.go b/api/utils_sanitise_test.go index e183f7e..cc27535 100644 --- a/api/utils_sanitise_test.go +++ b/api/utils_sanitise_test.go @@ -4,7 +4,7 @@ import ( "testing" ) -func TestStripEmailBasics(t *testing.T) { +func TestEmailStripBasics(t *testing.T) { tests := map[string]string{ "test@example.com": "test@example.com", "test+strip@example.com": "test@example.com", @@ -12,8 +12,8 @@ func TestStripEmailBasics(t *testing.T) { } for in, out := range tests { - if stripEmail(in) != out { - t.Errorf("for in=%s expected out=%s got out=%s", in, out, stripEmail(in)) + if emailStrip(in) != out { + t.Errorf("for in=%s expected out=%s got out=%s", in, out, emailStrip(in)) return } }