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

Backslash not removed when escaping quotes in strings #213

Closed
hugocaillard opened this issue Jan 12, 2022 · 6 comments · Fixed by #217
Closed

Backslash not removed when escaping quotes in strings #213

hugocaillard opened this issue Jan 12, 2022 · 6 comments · Fixed by #217
Assignees

Comments

@hugocaillard
Copy link
Collaborator

hugocaillard commented Jan 12, 2022

On clarinet the escaping backslashes are not removed in strings (ascii or utf8).
On the testnet it works as intended

Code to reproduce:

(define-public (say-hello)
  ;; returns `Hello \"World\"` instead of `Hello "World"`
  (ok "Hello \"World\"")
)

I also realised that backslashes are added before single quotes. Please tell me if I should open a second issue about that

(define-public (say-hello2)
  ;; returns `Hello \'World\'` instead of `Hello 'World'`
  (ok "Hello 'World'")
)
@lgalabru
Copy link
Contributor

Interesting, thanks for opening this issue.
Clarinet should probably be dumping .clar files in vector of bytes that we would pass to the clarity-repl.
Thoughts @obycode?

@obycode
Copy link
Member

obycode commented Jan 12, 2022

Interesting... the string is un-escaped after the parser. I'll dig into it a bit more.

@obycode obycode self-assigned this Jan 12, 2022
@obycode
Copy link
Member

obycode commented Jan 13, 2022

I believe the problem is that the result of mine block is being processed by a format! (deno.rs:1218)

    Some(output) => format!("{}", output),

And the implementation for the String clarity value uses this function from clarity/types/mod.rs:415:

impl fmt::Display for ASCIIData {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut escaped_str = String::new();
        for c in self.data.iter() {
            let escaped_char = format!("{}", std::ascii::escape_default(*c));
            escaped_str.push_str(&escaped_char);
        }
        write!(f, "{}", format!("\"{}\"", escaped_str))
    }
}

I should be able to fix it tomorrow.

obycode added a commit that referenced this issue Jan 15, 2022
@obycode
Copy link
Member

obycode commented Jan 15, 2022

Ok, I've got a fix in 5505ad8. I'm going to add some unit tests before opening a PR. I've basically just added a recursive function to print the Values instead of using the Display trait as defined in the clarity library, since that is where the character encoding happens. If either of you have a better name for this function, let me know (currently value_to_string).

@hugocaillard
Copy link
Collaborator Author

Tested locally and it's fixed 🙌
Thx

blockstack-devops pushed a commit that referenced this issue Jan 19, 2022
# [0.24.0](v0.23.1...v0.24.0) (2022-01-19)

### Bug Fixes

* fixed broken links ([b0f073a](b0f073a))
* generate proper strings from contract results ([6b189c6](6b189c6)), closes [#213](#213)
* only code-sign on release ([e10f3d1](e10f3d1))
* resolve bug with windows build in CI ([16ccd00](16ccd00))

### Features

* added ignore and only options to clarinet test ([a57cc23](a57cc23))
@blockstack-devops
Copy link
Collaborator

🎉 This issue has been resolved in version 0.24.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

4 participants