Issue with UTF-8 in yaml_read

Hello,

I have issues parsing an UTF-8-YAML string using yaml_read. Do I miss something or is it a bug?
I use Ubuntu and currently have this libyaml version installed:

libyaml-0-2/noble,now 0.2.5-1build1 amd64 [Installiert,automatisch]

Kind regards,
Wolfram.

$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4)
%...

[trace]  ?- yaml_read(string("name: Kovacs"),Yaml).
   Call: (10) yaml:yaml_read(string("name: Kovacs"), _1326) ? up
Yaml = yaml{name:"Kovacs"}.

[trace]  ?- yaml_read(string("name: Kovács"),Yaml).
   Call: (10) yaml:yaml_read(string("name: Kovács"), _4448) ? up
ERROR: Unknown error term: yaml_error(2,"invalid trailing UTF-8 octet")
ERROR: In:
ERROR:   [13] yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6630)
ERROR:   [12] setup_call_catcher_cleanup(yaml:yaml_open(...,<stream>(0x61fe3cd67c60),...),yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6686),_6658,yaml:close(<stream>(0x61fe3cd67c60))) at /usr/lib/swi-prolog/boot/init.pl:679
ERROR:   [11] setup_call_cleanup(yaml:yaml_open(...,<stream>(0x61fe3cd67c60),...),yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6750),yaml:close(<stream>(0x61fe3cd67c60))) at /usr/lib/swi-prolog/boot/init.pl:682
ERROR:   [10] yaml:yaml_read(string("name: Kovács"),_6792) at /usr/lib/swi-prolog/library/yaml.pl:96
ERROR:    [9] toplevel_call(user:user: ...) at /usr/lib/swi-prolog/boot/toplevel.pl:1173
   Exception: (13) yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60), _5824) ? abort
% Execution Aborted
$ echo "Kovács" | hexdump -C
00000000  4b 6f 76 c3 a1 63 73 0a                           |Kov..cs.|

Surely is a bug :slight_smile: Fixed. Pushed a fix to GIT. You could install from PPA after the next release, build from source or use this Claude generated work-around:

:- use_module(library(yaml)).
:- use_module(library(memfile)).

yaml_read_string(String, DOM) :-
    setup_call_cleanup(
        new_memory_file(MF),
        ( setup_call_cleanup(
              open_memory_file(MF, write, Out, [encoding(utf8)]),
              write(Out, String),
              close(Out)),
          setup_call_cleanup(
              open_memory_file(MF, read, In, [encoding(octet)]),
              yaml_read(In, DOM),
              close(In))),
        free_memory_file(MF)).

Thank you! I like the suggested workaround :slight_smile:

Kind regards,
Wolfram.