Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ The package version runs on its own semver; the schema it is generated from is `

## Unreleased

## 0.150.2 (2026-11-25)

### Fixed

- **A world file keeps a file whose integer no double holds as written.** `world_file_bytes` and `write_world_file` rewrote such a file exact when they left the author fields out, while the npm SDK rewrote it rounded (`9007199254740993` as `...992`): one input, two answers. A file holding an integer a double cannot hold, or one too large for a double at all, now travels byte for byte, its author fields with it, in both packages. An integer past 2**53 that a double holds exactly (`9007199254740994`) is rewritten as before. The shared author-fields fixture's case 8 pins it.

## 0.150.1 (2026-11-24)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/onlyworlds/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.150.1"
__version__ = "0.150.2"
24 changes: 23 additions & 1 deletion src/onlyworlds/worldfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,28 @@ def _unread_object(src: Path | bytes) -> dict[str, Any] | None:
return doc if isinstance(doc, dict) else None


def _holds_unheld_integer(value: Any) -> bool:
"""Whether a read file holds an integer no double holds (``9007199254740993``, which the npm
SDK and every JavaScript reader read as ``...992``; an integer too large for a double at all):
rewriting it would leave the five readers with five answers, so the file travels byte for
byte, its author fields with it (the author-fields fixture's case 8). One past 2**53 that a
double holds exactly (``9007199254740994``) does not count. ``bool`` is no integer here."""
stack = [value]
while stack:
v = stack.pop()
if isinstance(v, dict):
stack.extend(v.values())
elif isinstance(v, list):
stack.extend(v)
elif isinstance(v, int) and not isinstance(v, bool) and not -(2**53) <= v <= 2**53:
try:
if float(v) != v:
return True
except OverflowError:
return True
return False


def _without_author_fields(body: dict[str, Any] | None) -> bytes | None:
"""An element-folder file's object (``_element_files``, else ``_unread_object``) without its
author fields, in the folder's own form (``_jsonfmt.encode``: two-space indent, a trailing
Expand Down Expand Up @@ -981,7 +1003,7 @@ def in_private(rel: str) -> bool:
body = elements.get(rel)
if body is None and not include_author_fields and _under_element_folders(rel):
body = _unread_object(files[rel])
bare = None if include_author_fields else _without_author_fields(body)
bare = None if include_author_fields or _holds_unheld_integer(body) else _without_author_fields(body)
plan.append((rel, files[rel] if bare is None else bare))
return top, plan

Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/author-fields.fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@
"elements/character/Spaced.JSON": "{\"id\":\"sp\", \"x_note\":{\"created_by\":\"kept, an extension's own\"}}"
},
"stripped": 0
},
{
"name": "an integer no double holds (9007199254740993, which a double reads as ...992) keeps the file's bytes, the five with them, in an element read as an element too; one past 2^53 that a double holds exactly (9007199254740994) is rewritten",
"files": {
"world.json": "{\n \"id\": \"0192a000-aaaa-7bbb-8ccc-000000000001\",\n \"name\": \"W\"\n}\n",
"elements/object/held--o2.json": "{\"id\":\"o2\",\"name\":\"Held\",\"x_ref\":9007199254740994,\"created_by\":\"u\"}",
"elements/object/unheld--o3.json": "{\"id\":\"o3\",\"name\":\"Unheld\",\"x_ref\":9007199254740993,\"created_by\":\"u\"}"
},
"default": {
"world.json": "{\n \"id\": \"0192a000-aaaa-7bbb-8ccc-000000000001\",\n \"name\": \"W\"\n}\n",
"elements/object/held--o2.json": "{\n \"id\": \"o2\",\n \"name\": \"Held\",\n \"x_ref\": 9007199254740994\n}\n",
"elements/object/unheld--o3.json": "{\"id\":\"o3\",\"name\":\"Unheld\",\"x_ref\":9007199254740993,\"created_by\":\"u\"}"
},
"stripped": 1
}
]
}
4 changes: 2 additions & 2 deletions tests/test_worldfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,8 @@ def test_a_share_carries_under_the_element_folders_only_what_the_reader_serves(t

# The same bytes as the npm SDK's test/fixtures/author-fields.fixture.json (both suites hold its sha256).
AUTHOR_FIXTURE = REPO / "tests" / "fixtures" / "author-fields.fixture.json"
AUTHOR_FIXTURE_SHA256 = "6943ce5a8c2cd7bf69f82facb6f1d545d87d68f5ea0104cc4d711d94e035898a"
AUTHOR_CASES = 7
AUTHOR_FIXTURE_SHA256 = "33835ede8b407868da8fef2857699c53e763879ad4bef7909376c75b31c48645"
AUTHOR_CASES = 8
AUTHOR_FIELDS = ["created_by", "changed_by", "changed_via", "changed_client", "doors"]


Expand Down
Loading