File tree Expand file tree Collapse file tree 2 files changed +5
-15
lines changed Expand file tree Collapse file tree 2 files changed +5
-15
lines changed Original file line number Diff line number Diff line change @@ -1461,15 +1461,6 @@ 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 ()
@@ -1483,16 +1474,13 @@ func isURL(fl FieldLevel) bool {
1483
1474
return false
1484
1475
}
1485
1476
1486
- if isFileURL (s ) {
1487
- return true
1488
- }
1489
-
1490
1477
url , err := url .Parse (s )
1491
1478
if err != nil || url .Scheme == "" {
1492
1479
return false
1493
1480
}
1481
+ isFileScheme := url .Scheme == "file"
1494
1482
1495
- if url .Host == "" && url .Fragment == "" && url .Opaque == "" {
1483
+ if ( isFileScheme && ( len ( url .Path ) == 0 || url . Path == "/" )) || ( ! isFileScheme && len ( url .Host ) == 0 && len ( url . Fragment ) == 0 && len ( url .Opaque ) == 0 ) {
1496
1484
return false
1497
1485
}
1498
1486
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