Page MenuHome

bpy.props.StringProperty with subtype 'BYTE_STRING' loses information
Closed, InvalidPublic

Description

Blender 2.76b, Ubuntu 14.04

When saving bytes to a StringProperty, all the information after the first null byte is lost.
Example:

import bpy

TEST_BYTES = b'foo\x00\x00\x00bar'

str_prop = bpy.props.StringProperty(subtype='BYTE_STRING')
bpy.types.Scene.test_str_bytes = str_prop
bpy.context.scene.test_str_bytes = TEST_BYTES

print('{} not equal to {}'.format(bpy.context.scene.test_str_bytes, TEST_BYTES))

assert bpy.context.scene.test_str_bytes == TEST_BYTES

Event Timeline

Sebastian Brachi (brachi) raised the priority of this task from to 90.
Sebastian Brachi (brachi) updated the task description. (Show Details)
Sebastian Brachi (brachi) edited a custom field.
Campbell Barton (campbellbarton) changed the task status from Unknown Status to Unknown Status.Jan 7 2016, 6:45 PM

Checked and this is a known limitation.

However you can use ID-Property API to access non-terminated byte strings.

ob["prop"] = b'hello\0world' 
print(ob["prop"])

{F271974}Here's a patch to add a note in the api docs about it, as it might not be trivial to fix it.