Skip to content

Fix: Correct string array parsing in slice handling #5

@tejas-rkd

Description

@tejas-rkd

This is an issue which impacts downstream syncthing cli parsing for string array parsing.

Fixes syncthing/syncthing#9058

Problem

When adding a new item to a slice of structs via CLI flags, if a struct field was a slice of strings (e.g., []string), the parsing logic in makeSliceItemBuilders would not correctly identify it as a string slice. This was because the switch statement was checking simplifyKind(fieldValue.Kind()) which would be reflect.Slice or reflect.Array, not the kind of the elements within the slice. (fixes syncthing/syncthing#9058)

Solution

As this repo is closed for contribution from other, I am unable to raise a PR but here are my changes tejas-rkd@7a6d10b

  1. Modified the makeSliceItemBuilders function in recli.go. The inner switch statement that handles reflect.Array and reflect.Slice now correctly uses elemKind := simplifyKind(fieldValue.Type().Elem().Kind()) to determine the type of the elements within the slice. This ensures that string slices are correctly identified and processed using ctx.StringSlice(flagName).

Testing

In Syncthing,

  1. Added a new device with single address and checked if UI shows the same address.
  2. Did 1. with 3 addresses and with double quotes.
  3. looking for more testcases...
    (ref: "syncthing cli config devices add" reflect error when using --addresses flag syncthing/syncthing#8503)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions