A simple snap, containing the file unisnap.py
:
#!/usr/bin/env python3
import sys
if __name__ == "__main__":
inp = sys.stdin.read()
print("This is the input")
print(repr(inp))
print("As bytes it is")
print([hex(ord(x)) for x in inp])
and snapcraft.yaml
of:
name: unisnap
base: core18
version: '1.00'
summary: I think snaps sod around with unicode
description: |
let us test this theory
grade: stable
confinement: strict
parts:
tabular:
plugin: dump
source: .
apps:
unisnap:
command: /usr/bin/python3 $SNAP/unisnap.py
Build with snapcraft
and install with snap install --dangerous unisnap_1.00_amd64.snap
. Now:
15:42 ~/Scra+/unisnap $ cat testfile.txt
├─sda1 8:1 0 487M 0 part /boot/efi
15:42 ~/Scra+/unisnap $ hexdump -C testfile.txt
00000000 e2 94 9c e2 94 80 73 64 61 31 20 20 20 20 38 3a |......sda1 8:|
00000010 31 20 20 20 20 30 20 20 20 34 38 37 4d 20 20 30 |1 0 487M 0|
00000020 20 70 61 72 74 20 2f 62 6f 6f 74 2f 65 66 69 0a | part /boot/efi.|
00000030
15:42 ~/Scra+/unisnap $ python3 /snap/unisnap/current/unisnap.py < testfile.txt This is the input
'├─sda1 8:1 0 487M 0 part /boot/efi\n'
As bytes it is
['0x251c', '0x2500', '0x73', '0x64', '0x61', '0x31', '0x20', '0x20', '0x20', '0x20', '0x38', '0x3a', '0x31', '0x20', '0x20', '0x20', '0x20', '0x30', '0x20', '0x20', '0x20', '0x34', '0x38', '0x37', '0x4d', '0x20', '0x20', '0x30', '0x20', '0x70', '0x61', '0x72', '0x74', '0x20', '0x2f', '0x62', '0x6f', '0x6f', '0x74', '0x2f', '0x65', '0x66', '0x69', '0xa']
15:43 ~/Scra+/unisnap $ unisnap < testfile.txt
ERROR: ld.so: object 'libgtk3-nocsd.so.0' from LD_PRELOAD cannot be preloaded (failed to map segment from shared object): ignored.
This is the input
'\udce2\udc94\udc9c\udce2\udc94\udc80sda1 8:1 0 487M 0 part /boot/efi\n'
As bytes it is
['0xdce2', '0xdc94', '0xdc9c', '0xdce2', '0xdc94', '0xdc80', '0x73', '0x64', '0x61', '0x31', '0x20', '0x20', '0x20', '0x20', '0x38', '0x3a', '0x31', '0x20', '0x20', '0x20', '0x20', '0x30', '0x20', '0x20', '0x20', '0x34', '0x38', '0x37', '0x4d', '0x20', '0x20', '0x30', '0x20', '0x70', '0x61', '0x72', '0x74', '0x20', '0x2f', '0x62', '0x6f', '0x6f', '0x74', '0x2f', '0x65', '0x66', '0x69', '0xa']
Observe that running it as a snap, through the command symlink, mangles stdin by changing its encoding. It would be good if snapd didn’t do this.
(It’s possible that something else is going on that breaks Python’s unicodeness? But regardless, I don’t think that running the command via snapd and running the command directly ought to do different things to stdin.)