feat(libSceNKWebKit): implement WTF::FileSystemImpl encodeForFileName, decodeFromFilename and lastComponentOfPathIgnoringTrailingSlash #14858

Merged
ashwin280802 merged 4 commits from upstream-pr/14858 into main 2026-11-05 19:25:54 +00:00
ashwin280802 commented 2026-11-01 20:45:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ashwin280802 on 2026-11-01T20:45:37Z.


What

Implements WTF::FileSystemImpl::encodeForFileName (DM39YN-X56M), decodeFromFilename (dlR6Z857IFs) and lastComponentOfPathIgnoringTrailingSlash (3TsXk8jA39E) in libSceNKWebKit, replacing three NotImplemented_nid_no_patch stubs.

Source: FileSystem.cpp L66-L210 at the revision the other NKWebKit entries pin. It is not measured on a console and the device's WebKit revision is unverified (debt entry updated).

  • encodeForFileName escapes control characters, DEL, space, the characters " % * / : < > ?, the backslash and |, and unpaired surrogates, as %XX or %+XXXX above 0xFF (uppercase hex). The result is 8-bit only if every output unit is at most 0xFF, as WTF's StringBuilder produces.
  • decodeFromFilename returns a null String for a truncated or non-hex escape.
  • lastComponentOfPathIgnoringTrailingSlash uses / (the PlayStation port is not OS(WINDOWS)) and keeps WebKit's unsigned wraparound for "a/", "/" and "a//".

Deliberate divergences: a null String reference throws where WebKit has undefined behaviour, and encoding past 2^31-1 units throws std::length_error where WebKit hits a release assertion.

No open PR implements these functions. #14303, #14345 and #14479 edit the same WtfString.cpp line (L918) as this change, #14479 and #14607 another (L1024), #14479 also WtfExports.hpp and Wtf.cpp, and #14387 Wtf.cpp (L782-L784). #13515 and #14152 edit Export.cpp (#14152 also InventoryExports.hpp) but the overlap tool could not compare them. Ten more edit only the NKWebKit debt file, as do all of the above, so a rebase conflict is possible.

Tested

Windows 11 (MinGW-W64 GCC 15.2.0) and Linux in Docker (lavapipe, WSL2), at 3932685367. New nkwebkit_wtf cases cover all 128 ASCII values, surrogates, 8-bit and 16-bit results, both hex cases, 15 malformed decode inputs, escapes cut off at the end of a shared substring, trailing-slash paths, non-shared empty strings and null references.
ctest --test-dir build-full -R nkwebkit -V (all nine NKWebKit suites), and the same nine on both systems:

9/9 Test #2361: nkwebkit_wtf ..................... Passed 0.01 sec
100% tests passed out of 9
9/9 Test #2361: nkwebkit_wtf ..................... Passed 0.02 sec
100% tests passed out of 9
9/9 Test #2301: nkwebkit_wtf ..................... Passed 0.00 sec
100% tests passed, 0 tests failed out of 9

python3 tools/check_conventions.py --base origin/main passes. I changed 57 conditions, statements and operators in the new code one at a time and the test failed on 53; the other four cannot be observed (two length guards need a string of several GiB, two reserve calls only set capacity).

Not covered by a test: the two > 2^31-1 length guards.
Not verified: behaviour on a console; the rest of the test suite was not run, only the NKWebKit tests.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5111399808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14858). Originally posted by [ashwin280802](https://github.com/ashwin280802) on 2026-11-01T20:45:37Z. --- ### What Implements `WTF::FileSystemImpl::encodeForFileName` (`DM39YN-X56M`), `decodeFromFilename` (`dlR6Z857IFs`) and `lastComponentOfPathIgnoringTrailingSlash` (`3TsXk8jA39E`) in `libSceNKWebKit`, replacing three `NotImplemented_nid_no_patch` stubs. Source: [FileSystem.cpp L66-L210](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/FileSystem.cpp#L66-L210) at the revision the other NKWebKit entries pin. It is not measured on a console and the device's WebKit revision is unverified (debt entry updated). - `encodeForFileName` escapes control characters, DEL, space, the characters `" % * / : < > ?`, the backslash and `|`, and unpaired surrogates, as `%XX` or `%+XXXX` above 0xFF (uppercase hex). The result is 8-bit only if every output unit is at most 0xFF, as WTF's `StringBuilder` produces. - `decodeFromFilename` returns a null `String` for a truncated or non-hex escape. - `lastComponentOfPathIgnoringTrailingSlash` uses `/` (the PlayStation port is not `OS(WINDOWS)`) and keeps WebKit's unsigned wraparound for `"a/"`, `"/"` and `"a//"`. Deliberate divergences: a null `String` reference throws where WebKit has undefined behaviour, and encoding past 2^31-1 units throws `std::length_error` where WebKit hits a release assertion. No open PR implements these functions. #14303, #14345 and #14479 edit the same `WtfString.cpp` line (L918) as this change, #14479 and #14607 another (L1024), #14479 also `WtfExports.hpp` and `Wtf.cpp`, and #14387 `Wtf.cpp` (L782-L784). #13515 and #14152 edit `Export.cpp` (#14152 also `InventoryExports.hpp`) but the overlap tool could not compare them. Ten more edit only the NKWebKit debt file, as do all of the above, so a rebase conflict is possible. ### Tested Windows 11 (MinGW-W64 GCC 15.2.0) and Linux in Docker (lavapipe, WSL2), at 3932685367. New `nkwebkit_wtf` cases cover all 128 ASCII values, surrogates, 8-bit and 16-bit results, both hex cases, 15 malformed decode inputs, escapes cut off at the end of a shared substring, trailing-slash paths, non-shared empty strings and null references. `ctest --test-dir build-full -R nkwebkit -V` (all nine NKWebKit suites), and the same nine on both systems: ``` 9/9 Test #2361: nkwebkit_wtf ..................... Passed 0.01 sec 100% tests passed out of 9 9/9 Test #2361: nkwebkit_wtf ..................... Passed 0.02 sec 100% tests passed out of 9 9/9 Test #2301: nkwebkit_wtf ..................... Passed 0.00 sec 100% tests passed, 0 tests failed out of 9 ``` `python3 tools/check_conventions.py --base origin/main` passes. I changed 57 conditions, statements and operators in the new code one at a time and the test failed on 53; the other four cannot be observed (two length guards need a string of several GiB, two `reserve` calls only set capacity). Not covered by a test: the two `> 2^31-1` length guards. Not verified: behaviour on a console; the rest of the test suite was not run, only the NKWebKit tests. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-02 03:50:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T03:50:15Z.

Review: APPROVED


Windows 11, WinLibs GCC 15.2.0 r7, Release. Head 3932685367 merged into upstream/main 93dbd0f82a:

  • the nine nkwebkit* suites and public_headers: 10/10 pass.
  • Mutation check: with : removed from the escape set in NeedsFileNameEscape, nkwebkit_wtf fails in the all-ASCII loop (line 839).

Checked against FileSystem.cpp at the pinned revision:

  • the escaped ASCII set is the same as WebKit's needsEscaping table (controls, space, " % * / : < > ? \ |, DEL);
  • unpaired surrogates are escaped using the previous and next units;
  • %XX up to 0xFF and %+XXXX above;
  • the decoder returns a null String for a truncated or non-hex escape;
  • an empty input is returned as is in both directions.

The two stated divergences (throwing on a null reference and past the length limit, where WebKit has UB or a release assert) are refusals rather than invented results.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5731907495 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14858#pullrequestreview-5731907495). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T03:50:15Z. **Review:** APPROVED --- Windows 11, WinLibs GCC 15.2.0 r7, Release. Head 3932685367 merged into upstream/main 93dbd0f82a: - the nine `nkwebkit*` suites and `public_headers`: 10/10 pass. - Mutation check: with `:` removed from the escape set in `NeedsFileNameEscape`, `nkwebkit_wtf` fails in the all-ASCII loop (line 839). Checked against `FileSystem.cpp` at the pinned revision: - the escaped ASCII set is the same as WebKit's `needsEscaping` table (controls, space, `" % * / : < > ? \ |`, DEL); - unpaired surrogates are escaped using the previous and next units; - `%XX` up to 0xFF and `%+XXXX` above; - the decoder returns a null `String` for a truncated or non-hex escape; - an empty input is returned as is in both directions. The two stated divergences (throwing on a null reference and past the length limit, where WebKit has UB or a release assert) are refusals rather than invented results.
BunnyFl commented 2026-11-04 18:48:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T18:48:43Z.

Review: APPROVED


@ashwin280802 approved again at ede1bb0eb4.

The rebase: git range-diff against my approved 3932685367 changes none of this PR's own +/- lines. The only differences are main's context lines around WtfExports.hpp. Because the earlier rebase (b86f430) broke the build without changing a PR line, I built it this time.

What I ran: head ede1bb0eb4, which already contains main 9ab6a281ea. Windows 11, WinLibs GCC 15.2.0, Release:

  • nkwebkit_wtf and public_headers pass (2 of 2).
  • Mutation: with '%' removed from the characters encodeForFileName escapes, nkwebkit_wtf aborts (0xc0000409). So the tests reach the new encoding.
  • tools/check_conventions.py --base upstream/main --head on the head: all checks passed.
  • pr_overlap.py --branch on the head:
    • #14303, #14345 and #14607 change nearby WtfString.cpp lines, #14387 changes tests/Wtf.cpp lines 782 and 784, and about 20 NKWebKit PRs change the export count on line 36 of docs/dev/debt/libSceNKWebKit.md, #15125 among them. Whichever lands later will need a rebase there.
    • It also lists #13486 under the same three exports. That PR only carries the old argument-less inventory stubs that this PR removes, for example int APS5_VABI _ZN3WTF14FileSystemImpl17encodeForFileNameERKNS_6StringE() in its Export.cpp. So it doesn't implement them.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5773899249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14858#pullrequestreview-5773899249). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T18:48:43Z. **Review:** APPROVED --- @ashwin280802 approved again at `ede1bb0eb4`. **The rebase:** `git range-diff` against my approved `3932685367` changes none of this PR's own `+`/`-` lines. The only differences are `main`'s context lines around `WtfExports.hpp`. Because the earlier rebase (`b86f430`) broke the build without changing a PR line, I built it this time. **What I ran:** head `ede1bb0eb4`, which already contains `main` `9ab6a281ea`. Windows 11, WinLibs GCC 15.2.0, Release: - `nkwebkit_wtf` and `public_headers` pass (2 of 2). - **Mutation:** with `'%'` removed from the characters `encodeForFileName` escapes, `nkwebkit_wtf` aborts (`0xc0000409`). So the tests reach the new encoding. - `tools/check_conventions.py --base upstream/main --head` on the head: all checks passed. - `pr_overlap.py --branch` on the head: - #14303, #14345 and #14607 change nearby `WtfString.cpp` lines, #14387 changes `tests/Wtf.cpp` lines 782 and 784, and about 20 NKWebKit PRs change the export count on line 36 of `docs/dev/debt/libSceNKWebKit.md`, #15125 among them. Whichever lands later will need a rebase there. - It also lists #13486 under the same three exports. That PR only carries the old argument-less inventory stubs that this PR removes, for example [`int APS5_VABI _ZN3WTF14FileSystemImpl17encodeForFileNameERKNS_6StringE()`](https://github.com/boykopovar/AnyPS5/blob/0bde10d243b63a08556f9ceda6912cf5fef2b824/core/libs/prx/libSceNKWebKit/Export.cpp#L10859) in its `Export.cpp`. So it doesn't implement them.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14858
No description provided.