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

[BUG] String.__repr__() does not handle escape quotes or complexe situations #2459

Closed
gabrieldemarmiesse opened this issue May 1, 2024 · 3 comments
Labels
bug Something isn't working good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library

Comments

@gabrieldemarmiesse
Copy link
Contributor

gabrieldemarmiesse commented May 1, 2024

Bug description

The current implementation of String.__repr__() is very simple and is enough for simple use cases. If the String has simple quotes and double quotes in it, then things start to break. We should also be able to handle \ and such. As a reminder the output of String.__repr__() should produce a String which can be copy-pasted into a mojo file to recreate the same string. (like in python)

From what I understand the implementation in CPython is here: https://github.com/python/cpython/blob/main/Objects/unicodeobject.c#L12256 and while it's complicated, this is because it handles Unicode, which we don't have yet in Mojo. If we only support ASCII, that should be enough for now.

Steps to reproduce

print(repr(String("''\'\\")))

should return a valid Mojo expression but returns "'''\' instead which is not a valid Mojo expression.

System information

Ubuntu 22.04
mojo 2024.4.2923 (f54d89e3)
modular 0.7.2 (d0adc668)
@gabrieldemarmiesse gabrieldemarmiesse added bug Something isn't working mojo-repo Tag all issues with this label labels May 1, 2024
@JoeLoser JoeLoser added the mojo-stdlib Tag for issues related to standard library label May 1, 2024
@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 1, 2024
@rparolin rparolin added the good first issue Good for newcomers label May 2, 2024 — with Linear
@helehex
Copy link
Contributor

helehex commented May 3, 2024

I was just gonna copy over my naïve lookup table, but maybe i should do it a little better

@helehex
Copy link
Contributor

helehex commented May 3, 2024

seems like theres some move towards unicode anyways

@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 3, 2024 — with Linear
@helehex
Copy link
Contributor

helehex commented May 3, 2024

here's a solution
#2493

@ematejska ematejska removed the mojo-stdlib Tag for issues related to standard library label May 6, 2024
@ematejska ematejska added the mojo-stdlib Tag for issues related to standard library label May 6, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers mojo-repo Tag all issues with this label mojo-stdlib Tag for issues related to standard library
Projects
None yet
Development

No branches or pull requests

5 participants