Skip to content

Bug(expr): split/rsplit with maxsplit=-1 discard the input entirely #308

Description

@uberware

Summary

split('a,b,c', ',', -1) returns [] — the input is discarded. RFC 0006 documents
maxsplit as splitting "at most maxsplit times" and defines nothing for a negative value,
so no reading supports returning an empty list. Python (whose str.split the function
otherwise follows) treats a negative maxsplit as "unlimited", returning ["a", "b", "c"].

Versions

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

Reproduction

from openjd.expr import parse_expression
for src in ("split('a,b,c', ',', -1)", "rsplit('a,b,c', ',', -1)"):
    r = parse_expression(src).evaluate_with_metrics()
    print(src, "->", str(r.value))    # -> [] for both

Expected vs actual

Expression Expected Actual
split('a,b,c', ',', -1) ["a", "b", "c"] (Python's reading) or an error []
rsplit('a,b,c', ',', -1) ["a", "b", "c"] or an error []

Either the Python reading or an explicit rejection would be defensible; silently returning
[] loses data with no textual support in the spec.

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