-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SNOW-761744 Added URL Validator and URL Encoder (#757)
- Loading branch information
1 parent
72ad913
commit e11a2a5
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gosnowflake | ||
|
||
import ( | ||
"net/url" | ||
"regexp" | ||
) | ||
|
||
var ( | ||
matcher, _ = regexp.Compile(`^http(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z@:])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\&\(\)\/\\\+&%\$#_=@]*)?$`) | ||
) | ||
|
||
func isValidURL(targetURL string) bool { | ||
if !matcher.MatchString(targetURL) { | ||
logger.Infof(" The provided URL is not a valid URL - " + targetURL) | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
func urlEncode(targetString string) string { | ||
// We use QueryEscape instead of PathEscape here | ||
// for consistency across Drivers. For example: | ||
// QueryEscape escapes space as "+" whereas PE | ||
// it as %20F. PE also does not escape @ or & | ||
// either but QE does. | ||
// The behavior of QE in Golang is more in sync | ||
// with URL encoders in Python and Java hence the choice | ||
return url.QueryEscape(targetString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters