Preventing invalid characters in app names (#1839)

closes #1823

<!-- This is an auto-generated description by cubic. -->
---
## Summary by cubic
Blocks invalid characters in app folder paths during rename and shows
cleaner error messages in App Details. Prevents OS rename failures and
removes confusing IPC prefixes from errors.

- **Bug Fixes**
- Validate new appPath on rename; reject < > : " | ? * / \ and control
characters when the path changes, with a clear error message.
- Replace alert() with showError() and strip the IPC wrapper text for
user-friendly errors.

<sup>Written for commit 14b3c0978c1da3b97ca6d33e67684c7ff872ab0a.
Summary will update automatically on new commits.</sup>

<!-- End of auto-generated description by cubic. -->
This commit is contained in:
Mohamed Aziz Mejri
2025-12-02 08:14:41 +01:00
committed by GitHub
parent dd14e67d48
commit 2ca14345b6
2 changed files with 22 additions and 11 deletions

View File

@@ -1202,6 +1202,20 @@ export function registerAppHandlers() {
throw new Error("App not found"); throw new Error("App not found");
} }
const pathChanged = appPath !== app.path;
if (pathChanged) {
const invalidChars = /[<>:"|?*\/\\]/;
const hasInvalidChars =
invalidChars.test(appPath) || /[\x00-\x1f]/.test(appPath);
if (hasInvalidChars) {
throw new Error(
`App path "${appPath}" contains characters that are not allowed in folder names: < > : " | ? * / \\ or control characters. Please use a different path.`,
);
}
}
// Check for conflicts with existing apps // Check for conflicts with existing apps
const nameConflict = await db.query.apps.findFirst({ const nameConflict = await db.query.apps.findFirst({
where: eq(apps.name, appName), where: eq(apps.name, appName),

View File

@@ -128,11 +128,10 @@ export default function AppDetailsPage() {
await refreshApps(); await refreshApps();
} catch (error) { } catch (error) {
console.error("Failed to rename app:", error); console.error("Failed to rename app:", error);
alert( const errorMessage = (
`Error renaming app: ${ error instanceof Error ? error.message : String(error)
error instanceof Error ? error.message : String(error) ).replace(/^Error invoking remote method 'rename-app': Error: /, "");
}`, showError(errorMessage);
);
} finally { } finally {
setIsRenaming(false); setIsRenaming(false);
} }
@@ -143,7 +142,6 @@ export default function AppDetailsPage() {
try { try {
setIsRenamingFolder(true); setIsRenamingFolder(true);
await IpcClient.getInstance().renameApp({ await IpcClient.getInstance().renameApp({
appId, appId,
appName: selectedApp.name, // Keep the app name the same appName: selectedApp.name, // Keep the app name the same
@@ -154,11 +152,10 @@ export default function AppDetailsPage() {
await refreshApps(); await refreshApps();
} catch (error) { } catch (error) {
console.error("Failed to rename folder:", error); console.error("Failed to rename folder:", error);
alert( const errorMessage = (
`Error renaming folder: ${ error instanceof Error ? error.message : String(error)
error instanceof Error ? error.message : String(error) ).replace(/^Error invoking remote method 'rename-app': Error: /, "");
}`, showError(errorMessage);
);
} finally { } finally {
setIsRenamingFolder(false); setIsRenamingFolder(false);
} }