Skip to content

~ stringifies maps with Java Map.toString() instead of Python dict repr #1341

Description

@Nuhiat-Arefin

~ converts each operand with JUEL's string converter, which falls back to Object.toString() for maps. A Jinjava map renders as {g=v}; Jinja2 renders the Python dict repr {'g': 'v'}.

Affected: master df50b0d7. Releases 2.7.6, 2.8.3 and 2.8.4 behave the same.

Reproduction

{{ {'g':'v'} ~ length }}

Jinja2 renders {'g': 'v'}. Jinjava renders {g=v}.

Direct output agrees between the engines: {{ {'g':'v'} }} renders {'g': 'v'} in both. A list operand also agrees ([1, 2]), so the difference is specific to map stringification through the concat path.

Root cause

StringConcatOperator.apply converts both operands with converter.convert(o, String.class) (src/main/java/com/hubspot/jinjava/el/ext/StringConcatOperator.java). The converter has no Python-style representation for maps, so the map's toString() value is used.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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