From e347d225701253192fadf8828afd622ee4ee1026 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Mon, 26 Dec 2022 14:03:00 -0500 Subject: [PATCH] Formatted file --- sanitize.go | 66 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 22 deletions(-) diff --git a/sanitize.go b/sanitize.go index 128d490..55d23fe 100644 --- a/sanitize.go +++ b/sanitize.go @@ -43,7 +43,8 @@ var emptySpace = []byte("") // Alpha returns only alpha characters. Set the parameter spaces to true if you // want to allow space characters. Valid characters are a-z and A-Z. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Alpha(original string, spaces bool) string { // Leave white spaces? @@ -57,7 +58,8 @@ func Alpha(original string, spaces bool) string { // AlphaNumeric returns only alphanumeric characters. Set the parameter spaces to true // if you want to allow space characters. Valid characters are a-z, A-Z and 0-9. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func AlphaNumeric(original string, spaces bool) string { // Leave white spaces? @@ -70,21 +72,24 @@ func AlphaNumeric(original string, spaces bool) string { } // BitcoinAddress returns sanitized value for bitcoin address -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func BitcoinAddress(original string) string { return string(bitcoinRegExp.ReplaceAll([]byte(original), emptySpace)) } // BitcoinCashAddress returns sanitized value for bitcoin `cashaddr` // address (https://www.bitcoinabc.org/2018-01-14-CashAddr/) -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func BitcoinCashAddress(original string) string { return string(bitcoinCashAddrRegExp.ReplaceAll([]byte(original), emptySpace)) } // Custom uses a custom regex string and returns the sanitized result. // This is used for any additional regex that this package does not contain. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Custom(original string, regExp string) string { // Return the processed string or panic if regex fails @@ -92,7 +97,8 @@ func Custom(original string, regExp string) string { } // Decimal returns sanitized decimal/float values in either positive or negative. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Decimal(original string) string { return string(decimalRegExp.ReplaceAll([]byte(original), emptySpace)) } @@ -100,7 +106,8 @@ func Decimal(original string) string { // Domain returns a proper hostname / domain name. Preserve case is to flag keeping the case // versus forcing to lowercase. Use the removeWww flag to strip the www sub-domain. // This method returns an error if parse critically fails. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Domain(original string, preserveCase bool, removeWww bool) (string, error) { // Try to see if we have a host @@ -135,7 +142,8 @@ func Domain(original string, preserveCase bool, removeWww bool) (string, error) // Email returns a sanitized email address string. Email addresses are forced // to lowercase and removes any mail-to prefixes. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Email(original string, preserveCase bool) string { // Leave the email address in its original case @@ -153,7 +161,8 @@ func Email(original string, preserveCase bool) string { // FirstToUpper overwrites the first letter as an uppercase letter // and preserves the rest of the string. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func FirstToUpper(original string) string { // Handle empty and 1 character strings @@ -167,19 +176,22 @@ func FirstToUpper(original string) string { } // FormalName returns a formal name or surname (for First, Middle and Last) -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func FormalName(original string) string { return string(formalNameRegExp.ReplaceAll([]byte(original), emptySpace)) } // HTML returns a string without any tags. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func HTML(original string) string { return string(htmlRegExp.ReplaceAll([]byte(original), emptySpace)) } // IPAddress returns an ip address for both ipv4 and ipv6 formats. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func IPAddress(original string) string { // Parse the IP - Remove any invalid characters first ipAddress := net.ParseIP( @@ -193,61 +205,71 @@ func IPAddress(original string) string { } // Numeric returns numbers only. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Numeric(original string) string { return string(numericRegExp.ReplaceAll([]byte(original), emptySpace)) } // PathName returns a formatted path compliant name. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func PathName(original string) string { return string(pathNameRegExp.ReplaceAll([]byte(original), emptySpace)) } // Punctuation returns a string with basic punctuation preserved. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Punctuation(original string) string { return string(punctuationRegExp.ReplaceAll([]byte(original), emptySpace)) } // Scripts removes all scripts, iframes and embeds tags from string. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Scripts(original string) string { return string(scriptRegExp.ReplaceAll([]byte(original), emptySpace)) } // SingleLine returns a single line string, removes all carriage returns. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func SingleLine(original string) string { return singleLineRegExp.ReplaceAllString(original, " ") } // Time returns just the time part of the string. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func Time(original string) string { return string(timeRegExp.ReplaceAll([]byte(original), emptySpace)) } // URI returns allowed URI characters only. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func URI(original string) string { return string(uriRegExp.ReplaceAll([]byte(original), emptySpace)) } // URL returns a formatted url friendly string. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func URL(original string) string { return string(urlRegExp.ReplaceAll([]byte(original), emptySpace)) } // XML returns a string without any tags - alias of HTML. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func XML(original string) string { return HTML(original) } // XSS removes known XSS attack strings or script strings. -// View examples: sanitize_test.go +// +// View examples: sanitize_test.go func XSS(original string) string { original = strings.Replace(original, "", "", -1)