asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.06k stars 556 forks source link

add absolute and relative file path validator for Unix & Windows #278 #422

Closed ArshiAAkhavan closed 3 years ago

ArshiAAkhavan commented 3 years ago

Description

since the IsFilePath() function just checked the absolute paths #278, I've added IsUnixFilePath() & IsWinFilePath() functions for checking both absolutes and relative file paths in Unix and Windows.
Example: isUnixFilePath("relative_file_path") => true isUnixFilePath("./relative_file_path") => true isUnixFilePath("../relative_file_path") => true

isWinFilePath("relative_file_path") => true isWinFilePath("..\relative_file_path") => true isWinFilePath("..\\relative_file_path") => false

IsUnixFilePath() & IsWinFilePath() functions are using UnixARPath & WinARPath regex in patterns.go there are TestIsWinFilePath() & TestIsWinFilePath() test functions in validator_test.go for to demonstrate more