denoland / denoland/deno_cache_dir
Bug: HttpCache.set with `data:` scheme always throws error
- Dominant language
- TypeScript
- Stars
- 49
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
## minimal reproduction
```ts
import { HttpCache } from "@deno/cache-dir";
const httpCache = await HttpCache.create({
root: "",
vendorRoot:
"",
readOnly: false,
});
httpCache.set(
new URL("data:text/javascript"),
{},
Deno.readFileSync(
""
)
);
```
## Error
```
panicked at rs_lib/src/local.rs:673:67:
index out of bounds: the len is 0 but the index is 0
```
## Problem
`local.rs`
```rust
let scheme = base_parts.remove(0);
base_parts[0] = Cow::Owned(format!("{}_{}", scheme, base_parts[0]));
```
https://github.com/denoland/deno_cache_dir/blob/main/rs_lib/src/local.rs#L673
`common.rs`
```rust
pub fn base_url_to_filename_parts<'a>(
url: &'a Url,
port_separator: &str,
) -> Option>> {
match scheme {
"data" | "blob" => {
out.push(Cow::Borrowed(scheme));
}
};
```
https://github.com/denoland/deno_cache_dir/blob/main/rs_lib/src/common.rs#L34
Because of the `data:` scheme, there is only one Vec.push() happening, so the vector will always have length 1.
Vec.remove mutates the vector from length 1 to length 0 and then the vector is accessed at index 0.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with rs_lib/src/common.rs at base_url_to_filename_parts and rs_lib/src/local.rs around line 673, then run the minimal HttpCache.set reproduction using a data: URL. Done means the data: case no longer panics with an index-out-of-bounds error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, typescript
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100