diff --git a/regexes.go b/regexes.go index 0253d70..7161804 100644 --- a/regexes.go +++ b/regexes.go @@ -31,7 +31,7 @@ const ( aSCIIRegexString = "^[\x00-\x7F]*$" printableASCIIRegexString = "^[\x20-\x7E]*$" multibyteRegexString = "[^\x00-\x7F]" - dataURIRegexString = "^data:.+\\/(.+);base64$" + dataURIRegexString = `^data:((?:\w+\/(?:([^;]|;[^;]).)+)?)` latitudeRegexString = "^[-+]?([1-8]?\\d(\\.\\d+)?|90(\\.0+)?)$" longitudeRegexString = "^[-+]?(180(\\.0+)?|((1[0-7]\\d)|([1-9]?\\d))(\\.\\d+)?)$" sSNRegexString = `^[0-9]{3}[ -]?(0[1-9]|[1-9][0-9])[ -]?([1-9][0-9]{3}|[0-9][1-9][0-9]{2}|[0-9]{2}[1-9][0-9]|[0-9]{3}[1-9])$` diff --git a/validator_test.go b/validator_test.go index 2787f9e..4269dec 100644 --- a/validator_test.go +++ b/validator_test.go @@ -3435,12 +3435,15 @@ func TestDataURIValidation(t *testing.T) { {"data:image/png;base64,12345", false}, {"", false}, {"data:text,:;base85,U3VzcGVuZGlzc2UgbGVjdHVzIGxlbw==", false}, + {"data:image/jpeg;key=value;base64,UEsDBBQAAAAI", true}, + {"data:image/jpeg;key=value,UEsDBBQAAAAI", true}, + {"data:;base64;sdfgsdfgsdfasdfa=s,UEsDBBQAAAAI", true}, + {"data:,UEsDBBQAAAAI", true}, } validate := New() for i, test := range tests { - errs := validate.Var(test.param, "datauri") if test.expected {