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

fix: use internal QuotedString wrapper to quote Quil strings correctly #317

Merged
merged 1 commit into from
Nov 23, 2023

Conversation

Shadow53
Copy link
Contributor

Fixes #315.

This uses a new QuotedString wrapper with a custom Display impl to only escape quotation marks and backslashes in strings, and nothing else.

@kalzoo
Copy link
Contributor

kalzoo commented Nov 23, 2023

Thanks for the clear writeup and the fix with a test!

Comment on lines +330 to +336
for c in self.0.as_ref().chars() {
match c {
'"' => write!(f, "\\\"")?,
'\\' => write!(f, "\\\\")?,
c => write!(f, "{}", c)?,
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect String::replace would be faster than this, but we'd need to benchmark it. I don't know how much the performance of this conversion matters, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is specifically inside of Display, so I think this might actually be faster. String::replace would be creating a new owned String and then calling its Display, which probably looks similar to this loop.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, fair point. 👍🏻

@Shadow53 Shadow53 merged commit 81ab580 into main Nov 23, 2023
13 checks passed
@Shadow53 Shadow53 deleted the 315-string-serialization branch November 23, 2023 01:01
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.

String serialization output does not match spec.
3 participants