denoland / deno_std

The Deno Standard Library
https://jsr.io/@std
MIT License
2.83k stars 582 forks source link

url: when passed argument is not a valid url, error throwed. #5202

Closed familyboat closed 3 days ago

familyboat commented 3 days ago

Code snippet:

import {basename} from '@std/url';

// Learn more at https://deno.land/manual/examples/module_metadata#concepts
if (import.meta.main) {
 const invalidUrl = '/path/to/your/file';
 basename(invalidUrl);
}

When you run above code, error throwed. You can get more information in https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

familyboat commented 3 days ago

This issue is prevalent in the URL module, yet there is no mention of it in the documentation. Perhaps we could improve the documentation, or we might consider narrowing the range of acceptable input parameters.

iuioiua commented 3 days ago

The @std/url package handles URLs, not paths. This is expected behavior. I think you're looking for basename() from @std/path.

I'll close this issue. Please feel free to re-open if you feel there's a need.

familyboat commented 3 days ago

I agree with the point you mentioned; users also have the responsibility to ensure they are using the corresponding features as required. I am just a bit excited and looking forward to the upcoming stable version, and I have done some checks to the best of my ability. Your work is highly valuable.