Skip to content

Commit 1e9c063

Browse files
committed
better handle invalid project names and spaced paths
Signed-off-by: Luke-zhang-04 <[email protected]>
1 parent ed81da3 commit 1e9c063

File tree

11 files changed

+56
-17
lines changed

11 files changed

+56
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.5] - 2020-03-19
8+
9+
### Fixes
10+
- Handle paths with spaces better
11+
12+
713
## [2.0.4] - 2020-03-18
814

915
### Fixed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "processing-vscode",
33
"displayName": "Processing VSCode",
44
"description": "Processing Language Support for VSCode",
5-
"version": "2.0.3",
5+
"version": "2.0.5",
66
"publisher": "Luke-zhang-04",
77
"engines": {
88
"vscode": "^1.48.0"

rollup.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import typescript from "@rollup/plugin-typescript"
66

77
const banner = `/**
88
* processing-vscode - Processing Language Support for VSCode
9-
* @version 2.0.3
9+
* @version 2.0.5
1010
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
1111
* @preserve
1212
*/
@@ -35,6 +35,7 @@ const config = {
3535
process.env.NODE_ENV === "dev" ? undefined : terser({
3636
format: {
3737
comments: (_, {value}) => (
38+
((/@preserve/).test(value) || !(/processing-vscode/ui).test(value)) &&
3839
(/@preserve|li[cs]ense|copyright/ui).test(value)
3940
),
4041
}

src/commands/run.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

7-
import {dirname} from "path"
7+
import path, {dirname} from "path"
88
import {getProcessingCommand} from "../getConfig"
9+
import {isValidProcessingProject} from "../utils"
910
import vscode from "vscode"
1011

1112
class RunManager {
@@ -24,13 +25,24 @@ class RunManager {
2425
const currentTerminal = (this._terminal ??= // Readability 100
2526
vscode.window.terminals.find((terminal) => terminal.name === "Processing") ??
2627
vscode.window.createTerminal("Processing"))
28+
let sketchName = dirname(editor.document.fileName)
29+
const isValidProjectName = isValidProcessingProject(sketchName.split(path.sep).pop())
30+
const shouldQuotePath = sketchName.includes(" ")
31+
32+
if (shouldQuotePath) {
33+
sketchName = `"${sketchName}"`
34+
}
2735

2836
currentTerminal.show()
2937

38+
if (!isValidProjectName) {
39+
vscode.window.showWarningMessage(
40+
"Warning: Processing project names must be valid Java variable names. Your program may fail to run properly.",
41+
)
42+
}
43+
3044
// If file is a processing project file
31-
const cmd = `${getProcessingCommand()} --sketch="${dirname(
32-
editor.document.fileName,
33-
)}" --run`
45+
const cmd = `${getProcessingCommand()} --sketch=${sketchName} --run`
3446

3547
currentTerminal.sendText(cmd)
3648
}

src/diagnostics.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

7+
import path, {dirname} from "path"
78
import childProcess from "child_process"
89
import crypto from "crypto"
9-
import {dirname} from "path"
1010
import {getProcessingCommand} from "./getConfig"
11+
import {isValidProcessingProject} from "./utils"
1112
import vscode from "vscode"
1213

1314
let oldHash = ""
@@ -37,12 +38,23 @@ const refreshDiagnostics = async (
3738
): Promise<void> => {
3839
try {
3940
const foundDiagnostics: vscode.Diagnostic[] = []
40-
const sketchName = doc.fileName.includes(".pde") ? dirname(doc.fileName) : undefined
41+
let sketchName = doc.fileName.includes(".pde") ? dirname(doc.fileName) : undefined
4142

42-
if (sketchName && doc.getText()) {
43+
if (
44+
sketchName &&
45+
doc.getText() &&
46+
isValidProcessingProject(sketchName.split(path.sep).pop())
47+
) {
48+
const shouldQuotePath = sketchName.includes(" ")
49+
50+
if (shouldQuotePath) {
51+
sketchName = `"${sketchName}"`
52+
}
53+
54+
console.log({sketchName})
4355
const diagnostic = await new Promise<string[]>((resolve) => {
4456
const processingProcess = childProcess.spawn(getProcessingCommand(), [
45-
`--sketch=${dirname(doc.fileName)}`,
57+
`--sketch=${sketchName}`,
4658
"--build",
4759
])
4860

src/documentation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

src/getConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

src/search.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* processing-vscode - Processing Language Support for VSCode
3-
* @version 2.0.3
3+
* @version 2.0.5
44
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
55
*/
66

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* processing-vscode - Processing Language Support for VSCode
3+
* @version 2.0.5
4+
* @copyright (C) 2016 - 2020 Tobiah Zarlez, 2021 Luke Zhang
5+
*/
6+
7+
export const isValidProcessingProject = (path?: string): boolean =>
8+
path !== undefined && /^[\/_$a-z][\/\w$]*$/.test(path)

0 commit comments

Comments
 (0)