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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ The package version runs on its own semver; the schema it is generated from is `

## Unreleased

## 0.159.1 (2026-11-30)

- **Fixed: a folder `write_folder` writes always packs into a world file.** `write_folder`, and so `export_world` and the import doors, now also refuse an element id whose `<id>.json` the world file's name check refuses (folder spec 3.2): one holding `<`, `>`, `"`, `|`, `?` or `*`, a control character from U+007F to U+009F, or a Windows device name such as `con`. Before, such an id was written (on Windows, `a?b.json` stopped the write part-way with an OSError), and `world_file_bytes` then refused the folder. The refusal says why in the archive's words, `as "a?b.json" it holds a reserved or control character`. An id ending in a dot or a space is still written, since its file name ends in `.json`. The shared cases (`tests/fixtures/unsafe-ids.cases.json`, the same bytes as the npm SDK's) move with it: 22 refused, 5 written.

## 0.159.0 (2026-11-28)

- **Changed: the folder writer's collision rule compares names by the folder format's fold.** `resolve_filenames`, and so `write_folder`, the import doors and `export_world`, give two elements of one type whose short file names (slug and id tail) land on one name the id-ascending rule of folder spec §3.2: the lowest id keeps the short name, every other takes its full id. "One name" was `str.lower()` and is now the fold the archive reader compares names by (NFC, then simple case folding, Unicode 15.1), the same fold 0.158.6's refusal uses. So a few ids beyond ASCII now get the full-id name where before they were refused or lowercased apart: two elements named Bob with ids `a1234567ς` and `b1234567σ` kept the short names `bob--1234567ς.json` and `bob--1234567σ.json`, which the refusal joined, and are now written as `bob--1234567ς.json` and `bob--b1234567σ.json`. No ASCII id and no UUID changes its file name. The npm SDK's folder writer names them alike (`tests/fixtures/case-collide.cases.json`).
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.159.0"
__version__ = "0.159.1"
10 changes: 8 additions & 2 deletions src/onlyworlds/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ def _unsafe_id_why(element_id: str) -> str | None:
no slug, or the collision rule's full-id form) it must be one plain file name inside its type
folder. Checked in this order: empty (``.json``, a hidden file), a path separator, a colon (on Windows
``C:evil.json`` is a path on drive C, and ``a:b.json`` names a stream of file ``a``), a control
character (U+0000 to U+001F), ``.`` or ``..``. The npm SDK's writer refuses the same ids in the same
character (U+0000 to U+001F), ``.`` or ``..``, then whatever a world file's name check refuses for the
one segment ``<id>.json`` (folder spec 3.2: ``<>"|?*``, every other control character, a Windows device
name), so a folder that writes always packs. The npm SDK's writer refuses the same ids in the same
words (tests/fixtures/unsafe-ids.cases.json). ``_inside`` is the second guard, on the path itself."""
from .worldfile import _segment_fault # worldfile imports this module at load

if not element_id:
return "it is empty"
if _SEPARATOR.search(element_id):
Expand All @@ -207,7 +211,9 @@ def _unsafe_id_why(element_id: str) -> str | None:
return "it holds a control character"
if element_id in (".", ".."):
return "it is . or .."
return None
name = f"{element_id}.json"
fault = _segment_fault(name)
return f"as {json.dumps(name, ensure_ascii=False)} it {fault}" if fault is not None else None


def _inside(folder: Path, rel: str) -> bool:
Expand Down
21 changes: 15 additions & 6 deletions src/onlyworlds/worldfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,24 @@ def _path_fault(name: str) -> str | None:
_BAD_CHAR = re.compile('[<>:"|?*\x00-\x1f\x7f-\x9f]')


def _segment_fault(seg: str) -> str | None:
"""OW-22 for one segment: why it would not land on every disk, or None. The words name no segment, so
the folder writer's id check (``_unsafe_id_why``, on ``<id>.json``) says the same reason as an archive's."""
if _BAD_CHAR.search(seg):
return "holds a reserved or control character"
if seg.endswith((".", " ")):
return "ends in a dot or a space"
if seg.split(".")[0].upper() in _RESERVED:
return "is a Windows device name"
return None


def _name_fault(name: str) -> str | None:
"""OW-22: why a name would not land on every disk, or None."""
for seg in name.split("/"):
if _BAD_CHAR.search(seg):
return f"segment {seg!r} holds a reserved or control character"
if seg.endswith((".", " ")):
return f"segment {seg!r} ends in a dot or a space"
if seg.split(".")[0].upper() in _RESERVED:
return f"segment {seg!r} is a Windows device name"
fault = _segment_fault(seg)
if fault is not None:
return f"segment {seg!r} {fault}"
return None


Expand Down
21 changes: 18 additions & 3 deletions tests/fixtures/unsafe-ids.cases.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"about": "Element ids a world folder writer refuses and ids it writes: the npm SDK's folder writer (worldFolderFiles, convertKanka) and the Python package's write_folder. The same bytes in both repositories; both suites hold its sha256. An id is refused when used as <id>.json it would not be one plain file name: it is empty, it holds / or a backslash, it holds a colon (on Windows C:evil.json is a path on drive C), it holds a control character U+0000 to U+001F, or it is . or .. (checked in that order), whatever the name, since the collision rule can fall back to the full id. A refusal names the type, the id as JSON text and the why given here; no file is written. A written case gives the file's path. Cases written by hand.",
"about": "Element ids a world folder writer refuses and ids it writes: the npm SDK's folder writer (worldFolderFiles, convertKanka) and the Python package's write_folder. The same bytes in both repositories; both suites hold its sha256. An id is refused when used as <id>.json it would not be one plain file name: it is empty, it holds / or a backslash, it holds a colon (on Windows C:evil.json is a path on drive C), it holds a control character U+0000 to U+001F, or it is . or .. (checked in that order), or a world file's name check refuses the one segment <id>.json (<>\"|?*, every other control character, a Windows device name; folder spec §3.2), so a folder that writes always packs, whatever the name, since the collision rule can fall back to the full id. A refusal names the type, the id as JSON text and the why given here; no file is written. A written case gives the file's path. Cases written by hand.",
"version": 1,
"refused": [
{
Expand Down Expand Up @@ -96,6 +96,21 @@
"id": ":\u0000",
"name": "",
"why": "it holds a colon"
},
{
"id": "c-",
"name": "",
"why": "as \"c-.json\" it holds a reserved or control character"
},
{
"id": "a?b",
"name": "",
"why": "as \"a?b.json\" it holds a reserved or control character"
},
{
"id": "con",
"name": "",
"why": "as \"con.json\" it is a Windows device name"
}
],
"written": [
Expand All @@ -120,9 +135,9 @@
"path": "elements/character/dots--a..b.json"
},
{
"id": "c-",
"id": "a.",
"name": "",
"path": "elements/character/c-.json"
"path": "elements/character/a..json"
}
]
}
4 changes: 2 additions & 2 deletions tests/test_unsafe_ids.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from onlyworlds.okf import write_bundle

FIXTURE = Path(__file__).resolve().parent / "fixtures" / "unsafe-ids.cases.json"
FIXTURE_SHA256 = "cc6c0c016b441c0ebdc2840304f28c69e05a7ddf6eb0a333b343188717eb5581"
FIXTURE_SHA256 = "97638af150936cde866a08dd2919495f2d13e07aa6c9fd332b870c2198c74593"
W = {"id": "w-1", "name": "W"}


Expand All @@ -42,7 +42,7 @@ def test_the_cases_file_is_the_pinned_bytes() -> None:
assert hashlib.sha256(FIXTURE.read_bytes()).hexdigest() == FIXTURE_SHA256
data = _data()
assert data["version"] == 1
assert len(data["refused"]) == 19
assert len(data["refused"]) == 22
assert len(data["written"]) == 5


Expand Down
Loading