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

Pylightning: pass through non-ascii characters in the JSON input formatting #3018

Merged
merged 2 commits into from
Nov 29, 2019

Conversation

jarret
Copy link
Contributor

@jarret jarret commented Sep 2, 2019

Addresses issue #2753, which describes the problem and exception that was being seen.

This change enables non-ascii characters such as emojis to be included in the description field via pylightning:

Have done a bit of testing by passing in ascii strings: \ud83d\udc7d \\\\udc74 and \\udc7d seem to work as being interpreted as literal ascii rather than some unicode character, which is what is intended. I suspect the JSON encoding/decoding is handling this correctly in this mode.

@jarret jarret requested a review from cdecker as a code owner September 2, 2019 21:54
@rustyrussell
Copy link
Contributor

Definitely needs a test! We had an issue in the other direction, where we didn't handle RPC output properly.

But this doesn't seem to work when I tried it:

    def test_unicode_input(node_factory):
        l1 = node_factory.get_node()
    
        for s in [ '\ud83d\udc7d', '\\\\udc74', '\\udc7d' ]:
>           inv = l1.rpc.invoice(123000, s, s)

tests/test_invoices.py:498: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
contrib/pylightning/lightning/lightning.py:634: in invoice
    return self.call("invoice", payload)
contrib/pylightning/lightning/lightning.py:222: in call
    "id": self.next_id,
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <lightning.lightning.LightningRpc object at 0x7fa38c025e10>
sock = <socket.socket fd=12, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=lightning-rpc>
obj = {'id': 3, 'method': 'invoice', 'params': {'description': '\ud83d\udc7d', 'label': '\ud83d\udc7d', 'msatoshi': 123000}}

    def _writeobj(self, sock, obj):
        s = json.dumps(obj, ensure_ascii=False, cls=self.encoder_cls)
>       sock.sendall(bytearray(s, 'UTF-8'))
E       UnicodeEncodeError: 'utf-8' codec can't encode characters in position 63-64: surrogates not allowed

@cdecker
Copy link
Member

cdecker commented Nov 2, 2019

@rustyrussell I added a small test with some emojis and it seems to me that this addresses the issue correctly.

cdecker and others added 2 commits November 26, 2019 21:32
…s-is to the daemon

addresses issue ElementsProject#2753.

Formatting the JSON with the default parameters will escape the unicode
symbols in a way that c-lightning won't allow, leading to an exception.

Changelog-Fixed: `pylightning` now handles unicode characters in JSON-RPC requests and responses correctly.
@cdecker
Copy link
Member

cdecker commented Nov 26, 2019

ACK 1379435

@cdecker cdecker merged commit d712f73 into ElementsProject:master Nov 29, 2019
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.

3 participants