From ddf8a71da7997a10077a17c74b1e8919b7ce7099 Mon Sep 17 00:00:00 2001 From: Ahnaf An Nafee Date: Tue, 23 Dec 2025 12:02:34 -0500 Subject: [PATCH] Fix preview for filenames with special characters --- .github/workflows/release.yml | 15 +++++++++++++ ANTIGRAVITY.md | 37 +++++++++++++++++++++++++++++++ CHANGELOG.md | 4 ++++ examples/test (example).ps | Bin 0 -> 126 bytes examples/test example.ps | Bin 0 -> 126 bytes package.json | 2 +- src/preview.ts | 2 +- src/test/suite/extension.test.ts | 16 +++++++++++++ 8 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 ANTIGRAVITY.md create mode 100644 examples/test (example).ps create mode 100644 examples/test example.ps diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 630a47b..a761056 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -90,6 +90,20 @@ jobs: name: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix path: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix if-no-files-found: error + - name: Extract Changelog + if: (env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false') && success() + run: | + awk -v v="[${{ steps.package-version.outputs.current-version }}]" ' + /^## / { + if (index($0, v)) { + p=1 + next + } else { + p=0 + } + } + p { print } + ' CHANGELOG.md > RELEASE_BODY.md - name: Create release with artifact if: (env.VS_EXISTS == 'false' || env.OVSX_EXISTS == 'false') && success() uses: softprops/action-gh-release@v2.0.8 @@ -99,6 +113,7 @@ jobs: name: Release v${{ steps.package-version.outputs.current-version }} tag_name: v${{ steps.package-version.outputs.current-version }} draft: false + body_path: RELEASE_BODY.md files: postscript-preview-${{ steps.package-version.outputs.current-version }}.vsix - name: Publish to Open VSX Registry if: env.OVSX_EXISTS == 'false' diff --git a/ANTIGRAVITY.md b/ANTIGRAVITY.md new file mode 100644 index 0000000..d6314a0 --- /dev/null +++ b/ANTIGRAVITY.md @@ -0,0 +1,37 @@ +# Antigravity Guide + +## Project Overview + +**PostScript Preview** is a VS Code extension that renders previews for `.ps` and `.eps` files. + +- **Core Logic**: Uses `Ghostscript` (`ps2pdf`) to convert PS -> PDF, then `Poppler` (`pdftocairo`) to convert PDF -> SVG for display in a webview. +- **Languages**: TypeScript. + +## Build & Test + +- **Build**: `yarn compile` (runs `tsc`). +- **Test**: `yarn test` (runs VS Code extension tests via `mocha`). +- **Lint**: `yarn lint` (`eslint`). + +## Key Files + +- **`src/extension.ts`**: Entry point. Registers commands (`postscript-preview.sidePreview`). +- **`src/preview.ts`**: Core logic. + - `generatePreview()`: Handles the `ps2pdf` and `pdftocairo` pipeline. + - **CRITICAL**: usage of `spawnSync` for `ps2pdf` must use `{ shell: false }` to support special characters in filenames. +- **`src/webview.ts`**: Generates HTML content for the webview. +- **`src/config.ts`**: Manages configuration settings (paths to executables). +- **`src/test/suite/extension.test.ts`**: Integration tests. Includes cases for special character filenames. +- **`.github/workflows/release.yml`**: CI/CD for publishing. Automatically extracts changelog entries for release descriptions. + +## Workflows + +- **Release**: + 1. Bump version in `package.json`. + 2. Add entry to `CHANGELOG.md`. + 3. Push to `main`. The GitHub Action will build, test, package (`vsce`), and publish to Marketplace/OpenVSX. + +## Common Issues + +- **Ghostscript Warnings**: "no display font for 'ArialUnicode'" is a common benign warning from Ghostscript. +- **Filenames**: Always ensure command execution avoids shell injection (use `shell: false`). diff --git a/CHANGELOG.md b/CHANGELOG.md index e108e60..7f2d5c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Change Log +## [0.5.4] - 2025-12-23 + +- Fixed an issue where previewing files with special characters in the filename (e.g., spaces, parentheses) would fail with a syntax error. + ## [0.5.2] - 2025-12-17 - Fixed `Cannot find module 'path-scurry'` runtime error by downgrading `glob` dependency. diff --git a/examples/test (example).ps b/examples/test (example).ps new file mode 100644 index 0000000000000000000000000000000000000000..6d25e927b2944a943a160fe01fce53c627a7c7a6 GIT binary patch literal 126 zcmW-Z!4ASO3`6hz3h#gfCkkJ|5s3rmC`)OjY?+#f{XQ!P+j^4i)AW3$>qGP_(U?%$ zIu~05_Y7xJ`GZT0Ot+jdwAfL%bUt=!cw5&QrQ3pWpn|S-*6kMqjhjgDV@M?P+ Iw$Vq@4`MDV*8l(j literal 0 HcmV?d00001 diff --git a/examples/test example.ps b/examples/test example.ps new file mode 100644 index 0000000000000000000000000000000000000000..6d25e927b2944a943a160fe01fce53c627a7c7a6 GIT binary patch literal 126 zcmW-Z!4ASO3`6hz3h#gfCkkJ|5s3rmC`)OjY?+#f{XQ!P+j^4i)AW3$>qGP_(U?%$ zIu~05_Y7xJ`GZT0Ot+jdwAfL%bUt=!cw5&QrQ3pWpn|S-*6kMqjhjgDV@M?P+ Iw$Vq@4`MDV*8l(j literal 0 HcmV?d00001 diff --git a/package.json b/package.json index f2cdfbf..89eac22 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "postscript-preview", "displayName": "PostScript Preview", "description": "PostScript Preview is an extension that helps to preview EPS and PS files in Visual Studio Code.", - "version": "0.5.3", + "version": "0.5.4", "icon": "images/logo.png", "publisher": "ahnafnafee", "engines": { diff --git a/src/preview.ts b/src/preview.ts index 8aa3b9b..cd663db 100644 --- a/src/preview.ts +++ b/src/preview.ts @@ -115,7 +115,7 @@ export function generatePreview( const ps2pdfResult = spawnSync( config.ps2pdf, ["-dEPSCrop", filepath, pdfInfo.path], - { encoding: "utf-8", shell: true } + { encoding: "utf-8", shell: false } ); // Display any console output from GhostScript diff --git a/src/test/suite/extension.test.ts b/src/test/suite/extension.test.ts index 3132889..3bfabcc 100644 --- a/src/test/suite/extension.test.ts +++ b/src/test/suite/extension.test.ts @@ -44,4 +44,20 @@ suite("Extension Test Suite", () => { // Execute the command - validation fails if this throws await vscode.commands.executeCommand("postscript-preview.sidePreview"); }); + + test("Preview command should execute with special characters in filename", async () => { + // Ensure workspace is open + assert.ok(vscode.workspace.workspaceFolders, "No workspace is open"); + + const workspaceRoot = vscode.workspace.workspaceFolders[0].uri.fsPath; + const filePath = vscode.Uri.file( + workspaceRoot + "/examples/test (example).ps" + ); + + const doc = await vscode.workspace.openTextDocument(filePath); + await vscode.window.showTextDocument(doc); + + // Execute the command - validation fails if this throws + await vscode.commands.executeCommand("postscript-preview.sidePreview"); + }); });