Skip to content

Bug(expr): string(list[string]) fails to escape an embedded double quote, producing invalid JSON #312

Description

@uberware

Summary

RFC 0006 specifies string() on a list produces "the JSON string representation".
string(['a"b']) returns ["a"b"] — the embedded " is not escaped as \", so the output
is not valid JSON: the third " closes the string early.

Versions

  • openjd-model 0.11.1 and 0.11.2 from PyPI
  • openjd-rs main at 1a89f3a — still reproduces

Reproduction

import json
from openjd.expr import parse_expression
r = parse_expression("string(['a\"b'])").evaluate_with_metrics()
out = str(r.value)
print(out)               # -> ["a"b"]
json.loads(out)          # -> json.decoder.JSONDecodeError:
                         #    Expecting ',' delimiter: line 1 column 5 (char 4)

Why this is a bug

The output is consumed as JSON by construction ("the JSON string representation"), and this
one is rejected by any JSON parser. Note repr_json handles the same input correctly — the
escaping gap is specific to string()'s list path.

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