Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot delete contract files with special characters in filename #3979

Closed
DrCuriosity opened this issue Aug 17, 2022 · 2 comments · Fixed by #3981
Closed

Cannot delete contract files with special characters in filename #3979

DrCuriosity opened this issue Aug 17, 2022 · 2 comments · Fixed by #3981

Comments

@DrCuriosity
Copy link
Contributor

When attempting to delete a contract I'd resigned to the "too hard basket" the rm command failed, saying the file did not exist.

Output:

[zeus-med ~/]> ls
contract-45485-Bachman&Associates.cct 
[zeus-med ~/]> rm contract-45485-Bachman&Associates.cct
No such file exists
  • Version: v1.7.0
  • To reproduce: find a contract file containing a name like "Joe'sGuns" or "Bachman&Associates" and attempt to delete it with rm

I think this is happening because the apostrophe and ampersand characters are failing isValidFilename validation in the Terminal/DirectoryHelpers, where the regex only "Allows alphanumerics, hyphens, underscores, and percentage signs".

I'm of two minds about this could be fixed.

  1. Expanding the regex with \'\& symbols could work, but there could be a side-effect of validating some strings that shouldn't be considered valid, in some part of the system I don't yet understand.
  2. Altering the way contract filenames are generated to avoid or remove the invalid characters, e.g. "JoesGuns", "BachmanAssociates" or "BachmanAndAssociates", so that they pass validation. Might be more effort, but a more stable change (at least for filenames generated in future versions of the game).
@Snarling
Copy link
Contributor

Snarling commented Aug 17, 2022

Yeah it looks like you're right about it being the &. It's eventually reaching this filename check and failing to match this regex:

export function isValidFilename(filename: string): boolean {
// Allows alphanumerics, hyphens, underscores, and percentage signs
// Must have a file extension
const regex = /^[.a-zA-Z0-9_-]+[.][a-zA-Z0-9]+(?:-\d+(?:\.\d*)?%-INC)?$/;
// match() returns null if no match is found
return filename.match(regex) != null;
}

Edit: I just noticed you had already tracked down that it was this particular function...

@DrCuriosity
Copy link
Contributor Author

Have run into a new problem after the latest update, possibly related: I now can't directly run a file with an apostrophe in it without wrapping it in quotes.

[vitalife ~/]> run contract-134876-Joe'sGuns.cct 
No such contract
[vitalife ~/]> run "contract-134876-Joe'sGuns.cct"
Contract FAILED - 9 tries remaining

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 a pull request may close this issue.

2 participants