Skip to content

Fix glob pattern matching on Windows#524

Open
Frank3K wants to merge 1 commit intofirebase:masterfrom
Frank3K:fix-windows-glob-matching
Open

Fix glob pattern matching on Windows#524
Frank3K wants to merge 1 commit intofirebase:masterfrom
Frank3K:fix-windows-glob-matching

Conversation

@Frank3K
Copy link

@Frank3K Frank3K commented Feb 28, 2026

Description

Headers, redirects, and rewrites config rules are silently ignored on Windows. Any glob pattern without a leading slash — e.g. api/**, **/*.json — is never matched, so configured rules have no effect.

Root cause

glob-slasher (v1.0.1, 2014, unmaintained) depends on glob-slash, which normalizes patterns using Node's path module:

// node_modules/glob-slash/index.js
function normalize(value) {
  return path.normalize(path.join('/', value)); // ← uses OS path separator
}

On Windows, path.normalize converts forward slashes to backslashes. The pattern api/** becomes \api\**, which never matches a URL like /api/data.json.

Fix

Replace glob-slasher with a small local utility (src/utils/slasher.ts) that uses path.posix throughout, guaranteeing forward slashes on all platforms.

- const slasher = require("glob-slasher");
+ const { slasher } = require("../utils/slasher");

glob-slasher and its transitive dependencies (glob-slash, toxic, lodash.isobject, lodash._objecttypes) are removed from package.json.

Proof of concept (verified on Windows)

Create a directory with the following files and run npm install && npm start:

package.json

{
  "name": "superstatic-windows-glob-poc",
  "private": true,
  "scripts": {
    "start": "superstatic . -c config.json"
  },
  "dependencies": {
    "superstatic": "10.0.0"
  }
}

config.json

{
  "public": "public",
  "headers": [
    {
      "source": "api/**",
      "headers": [
        { "key": "X-Bug-Fixed", "value": "true" }
      ]
    }
  ]
}

public/api/data.json

{
  "message": "If the response includes 'X-Bug-Fixed: true', the glob pattern
matched correctly.",
  "expected_header": "X-Bug-Fixed: true"
}

Then verify with:

curl -I http://localhost:3474/api/data.json
Version X-Bug-Fixed header
superstatic@10.0.0 (npm) absent — rule never matched
this branch true — fixed

To reproduce with the fix, change the dependency to "superstatic": "https://github.com/Frank3K/superstatic.git#fix-windows-glob-matching" and re-run npm install.

Related PRs

…b matching

glob-slasher (v1.0.1, 2014, EOL) depends on glob-slash, which calls
path.normalize(path.join('/', value)). On Windows, path.normalize converts
forward slashes to backslashes, breaking glob pattern matching entirely —
e.g. /api/** becomes \api\** and never matches any request URL.

Replace it with a minimal local utility (src/utils/slasher.ts) that uses
path.posix throughout, guaranteeing forward slashes on all platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant