Closed Aerilius closed 6 years ago
Any output is transfered to the Console+ web dialog as JSON. The Ruby JSON library encodes to UTF-8. The binary string in Ruby defaulted to encoding UTF-8
, for which the byte is an invalid character. The binary string encoding should have been ASCII-8BIT
/BINARY
, however that cannot be converted to UTF-8 (Encoding::UndefinedConversionError: "\xFF" from ASCII-8BIT to UTF-8
).
An ideal fix would change Bridge to be able to transfer any byte strings to the web dialog.
to_json_raw_object
on the string, which 1. requires recursively traversing the input object to replace all problematic strings and 2. traversing the object again in JavaScript to replace the raw_object ({"json_class"=>"String", "raw"=>[255]}
) by the encoded JavaScript string.In output, the native console renders invalid characters like \xFF
(byte 255) with fallback glyphs (strangely
\uFFFF
).
But in input, it actually modifies the inserted string and replaces such characters in input by ?
(byte 63).
An appropriate solution is probably to suppress errors by replacing invalid characters for display of console output. It's much easier to implement in console.rb
input/result handling rather than traversing objects before JSON conversion.
When a string with non-UTF compatible characters (e.g. binary string) is output, a
JSON::GeneratorError
is raised.Example:
In SketchUp's native console, the string is output without error (although characters are not necessarily displayed).
Ruby Console+ should behave at least as good as the native console.