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

Illegal characters in file name or script are replaced by "!", and a … #967

Closed
wants to merge 1 commit into from

Conversation

david-pfx
Copy link
Contributor

…warning emitted.

Fixes #932

Copy link

@cwboden cwboden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love where this is headed -- these changes should simplify the "It Just Works" side of things for new users

background_color=state.bgcolor;
}
htmlString = htmlString.replace(/___BGCOLOR___/g,background_color);
var title = state.metadata.title ? state.metadata.title : "PuzzleScript Game";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In JavaScript nulls are typically coalesced like:

var title = state.metadata.title || "PuzzleScript Game";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my C/C++/C# showing up! I do know the JS way, but in so much of this code this would be written as an if/else with braces, I thought I was going out on a limb just making it a one-liner. But I approve the change.

return safeDollar(nv);
}

// replace $ because it's special in replace
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this comment -- open to rework it / remove it.

Maybe it'd be clear enough to name the function more verbosely, like sanitizeDollarCharacter()?
(And similarly, for safeUser above, IMO, though it's a nitpick)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original comments was
// $ has special meaning to JavaScript's String.replace
so I was sticking somewhere near.

Again, happy to approve a change that makes it easier for the reader.

What are the mechanics to do that?

htmlString = htmlString.replace(/"__GAMEDAT__"/g,sourceCode);
// $ has special meaning, so replace it by \v, then switch it back
htmlString = htmlString.replace(/"__GAMEDAT__"/, safeDollar(sourceCode));
htmlString = htmlString.replace(/\v/g, '$$');
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the \v approach more than doubling all of our $s. Nice! 👍

var BB = get_blob();
var blob = new BB([htmlString], {type: "text/plain;charset=utf-8"});
saveAs(blob, title+".html");
saveAs(blob, fn);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we could also replace the comment here with a more descriptive name than fn, like removeBadWindowsCharsFn

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. But it's not a function, so maybe filename?

@increpare
Copy link
Owner

increpare commented Dec 3, 2024

I had fixed that in a different way, by escaping the characters (hopefully) safely rather than replacing them, but forgot to close this issue. Thanks for the suggested change though!

@increpare increpare closed this Dec 3, 2024
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 this pull request may close these issues.

Some chars in prelude tags are not escaped properly, and these can cause exported games to fail compilation
3 participants