Merge pull request #548 from JonathanWThom/jt/datauri

Improves accuracy of datauri regex
pull/564/head
Dean Karn 5 years ago committed by GitHub
commit 5356060ec3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      regexes.go
  2. 5
      validator_test.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])$`

@ -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 {

Loading…
Cancel
Save