Skip to content

fix: escape Unicode and reserved characters in Gerber serialization - #52

Merged
hydra merged 4 commits into
MakerPnP:masterfrom
nicolube:fix/unicode-escape
Oct 8, 2026
Merged

hydra merged 4 commits into
MakerPnP:masterfrom
nicolube:fix/unicode-escape

Conversation

@nicolube

@nicolube nicolube commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread src/codegen.rs Outdated

/// Format a Gerber string or field as printable ASCII with Unicode escapes.
/// Names and macro expressions have their own syntax and must not use this helper.
pub(crate) struct Escaped<'a>(pub(crate) &'a str, pub(crate) bool);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

from the code in this PR, it's entirely unclear to me why the bool argument exists.

  • there are no comments by it's definition indicating what it might do.
  • all the code that uses it has true or false, there are no named constants anywhere that give a hint.

Without understanding it, it feels like there are two potention paths, assuming false means unescaped/raw:

  1. rename Escaped to MaybeEscaped with two enum values, Escaped and Raw, eliminating the boolean.
  2. change the bool argument to be an enum value with two options Escaped and Raw, but this won't read well where it's used.
  3. something else, perhaps using Into<...> instead if Escaped and provide conversion methods as appropriate?

Not sure, but one thing I do know from scanning this PR, is that bool doesn't seem to be the right answer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The bool defines whatever it is type string or field, the diffrence here is in commas should be escaped or not

Would it be better if weturn the thing into an enum like EscapedGerberText::String(text) and EscapedGerberText::Field(text)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed some changes, should be more clear now...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so much better now! thanks for sticking with me on this.

@nicolube
nicolube requested a review from hydra October 8, 2026 15:23
@hydra
hydra merged commit 5017cc4 into MakerPnP:master Oct 8, 2026
4 checks passed
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.

2 participants