gstack icon indicating copy to clipboard operation
gstack copied to clipboard

browse screenshot: relative paths starting with . are misidentified as CSS selectors

Open FeilixX opened this issue 8 months ago • 0 comments

Summary

browse screenshot ./path/to/file.png and browse screenshot .gstack/screenshots/page.png fail with:

screenshot: Unexpected token "/" while parsing css selector "./path/to/file.png"

Absolute paths work fine: browse screenshot /tmp/file.png ✅

Root Cause

In browse/src/meta-commands.ts line ~119, the argument classifier checks:

if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {
  targetSelector = arg;
} else {
  outputPath = arg;
}

Any argument starting with . is classified as a CSS class selector. This catches relative paths like ./screenshots/page.png and .gstack/reports/page.png.

Suggested Fix

Add a file path check before the selector check:

const isFilePath = arg.includes('/') && /\.(png|jpe?g|webp|pdf)$/i.test(arg);
if (isFilePath) {
  outputPath = arg;
} else if (arg.startsWith('@e') || arg.startsWith('@c') || arg.startsWith('.') || arg.startsWith('#') || arg.includes('[')) {
  targetSelector = arg;
} else {
  outputPath = arg;
}

A file path containing / and ending with an image extension is unambiguously not a CSS selector.

Reproduction

$B goto "http://example.com"
$B screenshot /tmp/works.png          # ✅ works
$B screenshot ./fails.png             # ❌ "Unexpected token /"
$B screenshot .gstack/also-fails.png  # ❌ same error

Environment

  • gstack v0.11.18.2
  • WSL2 Ubuntu 24.04

FeilixX avatar Mar 25 '26 18:03 FeilixX