pantoniou / libfyaml

Fully feature complete YAML parser and emitter, supporting the latest YAML spec and passing the full YAML testsuite.
MIT License
239 stars 73 forks source link

quoting strings with comma in flow style #68

Closed MarDiehl closed 1 year ago

MarDiehl commented 1 year ago

I have the following content:

- Aa,
  Bb, C,
  D
- Eee,
  F, Gg,
  E

fy-dump -m flow-oneline test.yaml gives

[Aa, Bb, C, D, Eee, F, Gg, E]

where only the coloring of the commas indicates that the list contains 2 string entries, not 8. When using the library directly to convert to oneline flow style,

void to_flow(char **flow, int* length_flow, const char *mixed){                                   
  struct fy_document *fyd = NULL;                                                                   
  enum fy_emitter_cfg_flags emit_flags = FYECF_MODE_FLOW_ONELINE | FYECF_STRIP_LABELS | FYECF_STRIP_TAGS |FYECF_STRIP_DOC;

  fyd = fy_document_build_from_string(NULL, mixed, -1);                                             
  if (!fyd) {                                                                                       
    *length_flow = -1;                                                                              
    return;                                                                                         
  }                                                                                                 
  int err = fy_document_resolve(fyd);                                                               
  if (err) {                                                                                        
    *length_flow = -1;                                                                              
    return;                                                                                         
  }                                                                                                 

  *flow = fy_emit_document_to_string(fyd,emit_flags);                                               
  *length_flow = strlen(*flow);                                                                     

  fy_document_destroy(fyd);                                                                         
}

the coloring is lost and one gets a list with 8 entries. Is it possible to automatically add quotes to multiline strings?

pantoniou commented 1 year ago

Yeah, this is absolutely a bug. Will address shortly.

pantoniou commented 1 year ago

https://github.com/pantoniou/libfyaml/commit/007fb98cb244fb3173a9588b053aaad9e08ac773 should fix this; if so please close.

MarDiehl commented 1 year ago

@pantoniou: many thanks, works perfect for me. Is there the chance that you make a new release soon so that also people using package managers can benefit?