File tree Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Expand file tree Collapse file tree 2 files changed +9
-12
lines changed Original file line number Diff line number Diff line change @@ -1461,19 +1461,11 @@ func isURI(fl FieldLevel) bool {
1461
1461
panic (fmt .Sprintf ("Bad field type %s" , field .Type ()))
1462
1462
}
1463
1463
1464
- // isFileURL is the helper function for validating if the `path` valid file URL as per RFC8089
1465
- func isFileURL (path string ) bool {
1466
- if ! strings .HasPrefix (path , "file:/" ) {
1467
- return false
1468
- }
1469
- _ , err := url .ParseRequestURI (path )
1470
- return err == nil
1471
- }
1472
-
1473
1464
// isURL is the validation function for validating if the current field's value is a valid URL.
1474
1465
func isURL (fl FieldLevel ) bool {
1475
1466
field := fl .Field ()
1476
1467
1468
+ var err error
1477
1469
switch field .Kind () {
1478
1470
case reflect .String :
1479
1471
@@ -1483,8 +1475,11 @@ func isURL(fl FieldLevel) bool {
1483
1475
return false
1484
1476
}
1485
1477
1486
- if isFileURL (s ) {
1487
- return true
1478
+ if strings .HasPrefix (s , "file://" ) {
1479
+ var u * url.URL
1480
+ u , err = url .ParseRequestURI (s )
1481
+
1482
+ return err == nil && u .Path != ""
1488
1483
}
1489
1484
1490
1485
url , err := url .Parse (s )
Original file line number Diff line number Diff line change @@ -8255,7 +8255,9 @@ func TestUrl(t *testing.T) {
8255
8255
{"file:///c:/Windows/file.txt" , true },
8256
8256
{"file://localhost/path/to/file.txt" , true },
8257
8257
{"file://localhost/c:/WINDOWS/file.txt" , true },
8258
- {"file://" , true },
8258
+ {"file:" , false },
8259
+ {"file:/" , false },
8260
+ {"file://" , false },
8259
8261
{"file:////remotehost/path/file.txt" , true },
8260
8262
}
8261
8263
You can’t perform that action at this time.
0 commit comments