Skip to content

A valuable whose name is only whitespace counts as having a name of its own #355

Done

Description

@mmacy

PlayerView.valuable_names treats a gem or piece of jewellery whose name is only whitespace as a piece with a name of its own. The check in _item_names (src/osrlib/crawl/views.py, the add_valuable helper) is if valuable.name and valuable.name != _ROLLED_VALUABLE_NAMES[valuable.kind], so a name of " " is truthy and becomes a key. PileView.items has the same gap, because _pile_view shows valuable.name or valuable.kind, so the pile's entry is the blank string and not the kind.

Elsewhere osrlib counts a whitespace-only label as empty: SpellMode.display_name falls back to its key when the label is only whitespace (_label_from_key in src/osrlib/core/spells.py).

Repro

On main at a0cfb10 (2.9.0), a member carrying ValuableInstance(instance_id="valuable-0101", kind="gem", name=" ", value_gp=10):

>>> view.valuable_names, view.item_names["valuable-0101"]
({'valuable-0101': '   '}, 'gem')

Expected

A piece whose name is empty after stripping whitespace has no name of its own: it isn't a key in valuable_names (or in valuable_phrases, once #354 lands), and a pile's items shows its kind. A ValuableSpec with such a name is an authoring slip, so the alternative is for validate_adventure to refuse it; either way the view shouldn't show a blank name.

Found while writing the contract for #354, whose decisions keep the keys of valuable_names as they are, so the fix is its own change.

Activity

  1. mmacy commented on Nov 26, 2026

    @mmacy
    OwnerAuthor

    Fixed in #356. A name of whitespace alone is no name of its own, and the view trims the whitespace around a name, in valuable_names, valuable_phrases, and a pile's items.

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