Skip to content

dotNotationToYamlObject breaks content #708

@GaspardHuber

Description

@GaspardHuber

Description:
com.decathlon.tzatziki.utils.Mapper#dotNotationToYamlObject:
When passing as argument an array of XMLs the conversion of dotNotationToYamlObject splits the xml.
For example the yaml:

- "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<ACTPRDX xmlns=\"http://www.ctt.pt/services/BMS/MessageDefinitions/ACTPRDX_3_0\">\n\t</ACTPRDX>"

will be returned as

-  "<?xml version=\"1:
              0\" encoding=\"ISO-8859-1\"?>\n<ACTPRDX xmlns=\"http://www.ctt.pt/services/BMS/MessageDefinitions/ACTPRDX_3_0\">\n\t</ACTPRDX>"

This is because the regex for the dot notations is too permissive: (?>([ -]))(?![ "']?e)([^.:]+).((?>[^:]+)(?<!\d{4}-\d{2}-\d{2}T\d{2}):(?![ "']?e).)

I suggest to switch to a dot notation that matches only words (maybe separated by dashes?) for ex:

String captureDotNotation = "(?>([ \\-]*))" + matchOnlyIfNonRegexFlag + "(\\w+)\\.((?>[^:]+)(?<!\\d{4}-\\d{2}-\\d{2}T\\d{2}):" + matchOnlyIfNonRegexFlag + ".*)";

Steps to reproduce:

  • Add test:
  @Test
  void yamlDotPropertyWithXml() {
    Assertions.assertEquals(
        """
        [- "<?xml version=\\"1.0\\" encoding=\\"ISO-8859-1\\"?>\\n<ACTPRDX xmlns=\\"http://www.ctt.pt/services/BMS/MessageDefinitions/ACTPRDX_3_0\\">\\n\\t</ACTPRDX>"]
        """.trim().stripIndent(),
        Mapper.toYaml("""
        - "<?xml version=\\"1.0\\" encoding=\\"ISO-8859-1\\"?>\\n<ACTPRDX xmlns=\\"http://www.ctt.pt/services/BMS/MessageDefinitions/ACTPRDX_3_0\\">\\n\\t</ACTPRDX>"
        """.trim().stripIndent()));
  }
  • Implement read() for lists in TestMapperDelegate
    @Override
    public <E> E read(String content, Class<E> clazz) {
      if (clazz == List.class) {
        return (E) readAsList(content);
      }
      return null;
    }

  public List<String> readAsList(String content) {
    return List.of(content);
  }

Workaround
use Mapper.shouldConvertDotPropertiesToObject(false); in your local steps

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions