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

un-ascii string should not escape. #10

Closed
ch-yx opened this issue Jan 27, 2019 · 5 comments
Closed

un-ascii string should not escape. #10

ch-yx opened this issue Jan 27, 2019 · 5 comments

Comments

@ch-yx
Copy link

ch-yx commented Jan 27, 2019

>>> str(nbtlib.tag.String("我"))
'"\\\\u6211"'

as NBT String only support \" and \\ escape.

@vberlier
Copy link
Owner

Unicode escaping works as intended. In this case the extra backslashes are there because the python repl outputs a representation of the string to your terminal rather than the string itself:

>>>  = String('我')
>>> str()
'"\\\\u6211"'
>>> print(repr(str()))  # This is the code that the repl executes
'"\\\\u6211"'

If you want to display the actual nbt literal you just need to print the string directly:

>>> print(str())
"\\u6211"
>>> print()  # The `print` function internally calls `str`
"\\u6211"

@ch-yx
Copy link
Author

ch-yx commented Jan 28, 2019

but,command do not support escapes like \uxxxx.

2019-01-28_13 49 51
🤔

@vberlier
Copy link
Owner

Oh right my mistake I tested it with json text objects so I didn't realize that the reason why the escape sequence worked was because it was interpreted afterwards by the json parsing:

>>> print(Compound({'display': Compound({'Name': String('{"text":"我"}')})}))
{display:{Name:"{\"text\":\"\\u6211\"}"}}

So yeah I tried it out in a command and it worked:

/give @p minecraft:apple{display:{Name:"{\"text\":\"\\u6211\"}"}}

Anyway since bare strings seem to support unicode characters directly I think I'll just get rid of the escaping.

@vberlier vberlier reopened this Jan 28, 2019
@vberlier
Copy link
Owner

Alright escaping problems should be fixed in 97efa25.

@vberlier
Copy link
Owner

Closing the issue as the fix is now in release 1.3.1.

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

No branches or pull requests

2 participants