denoland / denoland/std

isGlob and globToRegExp do not support windows paths

Open
#5,434 6 comments 0 reactions 0 assignees View on GitHub
path
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**

**Steps to Reproduce**
```ts
import * as path from 'jsr:@std/path@1.0.0'

let globpath = 'D:\\a\\forager\\test\\resources\\*.jpg'
path.isGlob(globpath)
// false
path.globToRegExp(globpath)
// /^D:aforagertestresources\*\.jpg\/*$/
```

**Expected behavior**
I would expect to see globpath above return `true` for a filepath that contains `*` even on windows. I would also expect that `globToRegExp` would create a valid path delineated regex. See how these functions behave with unix paths below:
```ts
import * as path from 'jsr:@std/path@1.0.0'

let globpath = '/forager/test/resources/*.jpg'
path.isGlob(globpath)
// true
path.globToRegExp(globpath)
// /^\/+forager\/+test\/+resources\/+[^/]*\.jpg\/*$/
```

My best guess is that this is because globs are mainly used in unix systems. I am building a cross-platform app though that needs some kind of glob support for windows paths. For now I can fork these methods to be more cross-platform, but I think this is probably a good improvement to these utilities.

**Environment**

- OS: `ubuntu-latest` & `windows-latest` on github ci
- deno version: 1.44.1
- std version: `1.0.0`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.