feat(libSceNKWebKit): implement stripLeadingAndTrailingHTMLSpaces #18797

Merged
AlexWhitehouse merged 2 commits from upstream-pr/18797 into main 2026-11-18 11:04:05 +00:00
AlexWhitehouse commented 2026-11-12 09:58:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlexWhitehouse on 2026-11-12T09:58:21Z.


What

libSceNKWebKit WebCore::stripLeadingAndTrailingHTMLSpaces(const WTF::String&) (_ZN7WebCore33stripLeadingAndTrailingHTMLSpacesERKN3WTF6StringE, NID IUY0ho-22JE) threw not implemented. This PR ports it from WebKit c55364d5, the historical revision other NKWebKit ports here already use; the newer PS5-WebKit tree (80f77e94) no longer has this const String& overload.

Behaviour:

  • Null and empty: a null String returns null. An empty or all-space string returns WebKit's shared empty string, as emptyAtom().string() does upstream.
  • Nothing to trim: the same StringImpl comes back with one more reference, as return string does upstream.
  • Trimming: otherwise the result comes from the existing StringImpl::substring export, so its character width matches the input's.
  • Other characters: VT (U+000B), NBSP (U+00A0) and every other character are kept.
  • Return: the String is returned through the hidden sret pointer, like the other String-returning NKWebKit exports.
  • Storage: a non-empty string without character storage throws.

The new src/HtmlSpaceTrim.cpp starts with HTMLParserIdioms.cpp's notice. It reuses the existing String support without editing WtfString.cpp or WtfStringAbi.hpp. The stub and its legacy declaration are removed (it had no inventory row, so the NKWebKit count line is untouched), and a debt fragment, docs/dev/debt/changes/feat-libscenkwebkit-strip-html-spaces.md, adds an entry recording that the console's String layout and sret ABI are unverified.

Tested

  • New test: nkwebkit_htmlspacetrim (core/libs/prx/libSceNKWebKit/tests/HtmlSpaceTrim.cpp) runs every case on 8-bit and 16-bit strings:
    • empty and all-space input, which return the shared empty string;
    • leading, trailing and both-sided trimming, with inner spaces kept;
    • VT, NBSP and NUL kept;
    • each of the 256 Latin-1 characters around an x, trimmed only if it is one of the five HTML spaces;
    • the 8-bit flag of the result;
    • reference counts: an untrimmed string returns the same impl with one more reference, a trimmed one returns a new impl, and the input's count is back where it started afterwards.
  • Linux x86-64 (Ubuntu 26.04, GCC 15, Release):
    • on main, the test fails with _ZN7WebCore33stripLeadingAndTrailingHTMLSpacesERKN3WTF6StringE not implemented;
    • with this PR, nkwebkit_htmlspacetrim, nkwebkit_webcoreparsers, nkwebkit_wtf and public_headers pass.
  • Windows 11 (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): nkwebkit_htmlspacetrim, nkwebkit_webcoreparsers and nkwebkit_wtf pass at 0481db5a90, with no compiler warnings in the changed files. The branch was then rebased onto current main without conflicts, and the tests pass again on Linux.
  • Mutation check: treating VT as an HTML space fails the test.
  • python3 tools/check_conventions.py --base origin/main: all checks passed.
  • python3 tools/pr_overlap.py: no open PR implements this export.
    • Other open NKWebKit PRs share only neighbouring #include lines in libSceNKWebKit.hpp; the PR no longer touches the NKWebKit debt file. Whichever merges second rebases.
    • It couldn't compare 82 other NKWebKit PRs automatically. None of their diffs changes this export, its NID or the new files.
    • The String PRs (#14917–#14920, #14926–#14930, #14946–#14948, #18391) and #18175 (WebCoreParsers.cpp) aren't touched.

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:5275287488 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18797). Originally posted by [AlexWhitehouse](https://github.com/AlexWhitehouse) on 2026-11-12T09:58:21Z. --- ### What libSceNKWebKit `WebCore::stripLeadingAndTrailingHTMLSpaces(const WTF::String&)` (`_ZN7WebCore33stripLeadingAndTrailingHTMLSpacesERKN3WTF6StringE`, NID `IUY0ho-22JE`) threw `not implemented`. This PR ports it from WebKit c55364d5, the historical revision other NKWebKit ports here already use; the newer PS5-WebKit tree (80f77e94) no longer has this `const String&` overload. - [`HTMLParserIdioms.cpp` lines 39–76](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WebCore/html/parser/HTMLParserIdioms.cpp#L39-L76): the trimming itself; - [`HTMLParserIdioms.h` lines 91–109](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WebCore/html/parser/HTMLParserIdioms.h#L91-L109): `isHTMLSpace`, which is only TAB, LF, FF, CR and SPACE; - [`WTFString.cpp` lines 309–313](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/text/WTFString.cpp#L309-L313) and [`StringImpl.cpp` lines 324–339](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/text/StringImpl.cpp#L324-L339): `substring`. Behaviour: - **Null and empty:** a null String returns null. An empty or all-space string returns WebKit's shared empty string, as `emptyAtom().string()` does upstream. - **Nothing to trim:** the same `StringImpl` comes back with one more reference, as `return string` does upstream. - **Trimming:** otherwise the result comes from the existing `StringImpl::substring` export, so its character width matches the input's. - **Other characters:** VT (U+000B), NBSP (U+00A0) and every other character are kept. - **Return:** the String is returned through the hidden sret pointer, like the other String-returning NKWebKit exports. - **Storage:** a non-empty string without character storage throws. The new `src/HtmlSpaceTrim.cpp` starts with `HTMLParserIdioms.cpp`'s notice. It reuses the existing String support without editing `WtfString.cpp` or `WtfStringAbi.hpp`. The stub and its legacy declaration are removed (it had no inventory row, so the NKWebKit count line is untouched), and a debt fragment, `docs/dev/debt/changes/feat-libscenkwebkit-strip-html-spaces.md`, adds an entry recording that the console's String layout and sret ABI are unverified. ### Tested - **New test:** `nkwebkit_htmlspacetrim` (`core/libs/prx/libSceNKWebKit/tests/HtmlSpaceTrim.cpp`) runs every case on 8-bit and 16-bit strings: - empty and all-space input, which return the shared empty string; - leading, trailing and both-sided trimming, with inner spaces kept; - VT, NBSP and NUL kept; - each of the 256 Latin-1 characters around an `x`, trimmed only if it is one of the five HTML spaces; - the 8-bit flag of the result; - reference counts: an untrimmed string returns the same impl with one more reference, a trimmed one returns a new impl, and the input's count is back where it started afterwards. - **Linux x86-64** (Ubuntu 26.04, GCC 15, Release): - on `main`, the test fails with `_ZN7WebCore33stripLeadingAndTrailingHTMLSpacesERKN3WTF6StringE not implemented`; - with this PR, `nkwebkit_htmlspacetrim`, `nkwebkit_webcoreparsers`, `nkwebkit_wtf` and `public_headers` pass. - **Windows 11** (build 26300, WinLibs MinGW-w64 GCC 15.2.0 UCRT, Release): `nkwebkit_htmlspacetrim`, `nkwebkit_webcoreparsers` and `nkwebkit_wtf` pass at 0481db5a90, with no compiler warnings in the changed files. The branch was then rebased onto current `main` without conflicts, and the tests pass again on Linux. - **Mutation check:** treating VT as an HTML space fails the test. - `python3 tools/check_conventions.py --base origin/main`: all checks passed. - **`python3 tools/pr_overlap.py`:** no open PR implements this export. - Other open NKWebKit PRs share only neighbouring `#include` lines in `libSceNKWebKit.hpp`; the PR no longer touches the NKWebKit debt file. Whichever merges second rebases. - It couldn't compare 82 other NKWebKit PRs automatically. None of their diffs changes this export, its NID or the new files. - The String PRs (#14917–#14920, #14926–#14930, #14946–#14948, #18391) and #18175 (`WebCoreParsers.cpp`) aren't touched. ### 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)
PrivacyOnion commented 2026-11-12 10:25:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T10:25:23Z.

Review: CHANGES_REQUESTED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 94778ba91c:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_htmlspacetrim_tests built cleanly.
  • CTest (nkwebkit_htmlspacetrim):
    1/1 Test #3759: nkwebkit_htmlspacetrim ...........   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified input validation and null handling in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: null string.impl returns string unchanged, length == 0 returns NKWebKit::WtfAbi::EmptyStringImpl(), and non-empty strings with null data throw std::invalid_argument as documented in debt.
    • Verified character classification in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: IsHTMLSpace strictly matches the five HTML space characters (' ', '\t', '\n', '\r', '\f') and correctly preserves non-HTML spaces such as '\v' (U+000B) and NBSP (U+00A0).
    • Verified buffer indexing in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: characterAt correctly discriminates 8-bit (const unsigned char*) vs 16-bit (const char16_t*) character storage via impl->hashAndFlags & 4.
    • Verified trimming loop bounds in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: all-space inputs canonicalize to EmptyStringImpl, untrimmed strings return the input string without reallocating, and trimmed substrings correctly calculate offset and length without underflow.
    • Verified export declaration and stub cleanup: removed outdated stubs from core/libs/prx/libSceNKWebKit/Export.cpp and core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp, and exposed the new export in core/libs/prx/libSceNKWebKit/include/HtmlSpaceTrimExports.hpp.
    • Verified technical debt tracking: docs/dev/debt/libSceNKWebKit.md documents the behavior, upstream WebKit references, and unverified console ABI.
  • Concerns:
    • core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:1-23: AGENTS.md explicitly states: 'No comments in code, except #endif and namespace ends.' Lines 1-23 contain a 23-line license header block comment in code, which violates this repository rule.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5872795282 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18797#pullrequestreview-5872795282). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T10:25:23Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `94778ba91c`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_htmlspacetrim_tests` built cleanly. - **CTest** (`nkwebkit_htmlspacetrim`): ``` 1/1 Test #3759: nkwebkit_htmlspacetrim ........... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp`, `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified input validation and null handling in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: null string.impl returns string unchanged, length == 0 returns NKWebKit::WtfAbi::EmptyStringImpl(), and non-empty strings with null data throw std::invalid_argument as documented in debt. - Verified character classification in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: IsHTMLSpace strictly matches the five HTML space characters (' ', '\\t', '\\n', '\\r', '\\f') and correctly preserves non-HTML spaces such as '\\v' (U+000B) and NBSP (U+00A0). - Verified buffer indexing in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: characterAt correctly discriminates 8-bit (const unsigned char*) vs 16-bit (const char16_t*) character storage via impl->hashAndFlags & 4. - Verified trimming loop bounds in core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp: all-space inputs canonicalize to EmptyStringImpl, untrimmed strings return the input string without reallocating, and trimmed substrings correctly calculate offset and length without underflow. - Verified export declaration and stub cleanup: removed outdated stubs from core/libs/prx/libSceNKWebKit/Export.cpp and core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp, and exposed the new export in core/libs/prx/libSceNKWebKit/include/HtmlSpaceTrimExports.hpp. - Verified technical debt tracking: docs/dev/debt/libSceNKWebKit.md documents the behavior, upstream WebKit references, and unverified console ABI. - **Concerns**: - core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:1-23: AGENTS.md explicitly states: 'No comments in code, except #endif and namespace ends.' Lines 1-23 contain a 23-line license header block comment in code, which violates this repository rule. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-12 14:17:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-12T14:17:17Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against d0e0a17de5:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_htmlspacetrim_tests built cleanly.
  • CTest (nkwebkit_htmlspacetrim):
    1/1 Test #3771: nkwebkit_htmlspacetrim ...........   Passed    0.01 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp, core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:33-35 against WebKit HTMLParserIdioms.h: verified IsHTMLSpace strictly matches the 5 HTML space characters (0x20, 0x0A, 0x09, 0x0D, 0x0C) while preserving VT (0x0B) and non-breaking space (0xA0).
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:44-46 for null pointer and empty string handling: verified null impl safely returns null string, length 0 canonicalizes to EmptyStringImpl, and non-empty strings with null data throw std::invalid_argument.
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:47-50 for character width handling: verified impl->hashAndFlags & 4 correctly selects between unsigned char (8-bit) and char16_t (16-bit) buffers without signedness or truncation defects across Linux LP64 and Windows LLP64.
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:51-57 for index bounds safety: verified leading == impl->length handles all-space strings safely, and trailing termination at or before impl->length - leading - 1 guarantees impl->length - leading - trailing >= 1 with no unsigned underflow.
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:56 for untrimmed preservation: verified !(leading | trailing) returns the input string directly to retain the existing StringImpl rather than allocating an identical copy.
    • Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp and docs/dev/debt/libSceNKWebKit.md against AGENTS.md: confirmed no forbidden inline comments exist, upstream copyright notice matches maintainer precedent, and technical debt entry is properly recorded.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5875957084 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/18797#pullrequestreview-5875957084). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-12T14:17:17Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `d0e0a17de5`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_htmlspacetrim_tests` built cleanly. - **CTest** (`nkwebkit_htmlspacetrim`): ``` 1/1 Test #3771: nkwebkit_htmlspacetrim ........... Passed 0.01 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/LegacyExports.hpp`, `core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:33-35 against WebKit HTMLParserIdioms.h: verified IsHTMLSpace strictly matches the 5 HTML space characters (0x20, 0x0A, 0x09, 0x0D, 0x0C) while preserving VT (0x0B) and non-breaking space (0xA0). - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:44-46 for null pointer and empty string handling: verified null impl safely returns null string, length 0 canonicalizes to EmptyStringImpl, and non-empty strings with null data throw std::invalid_argument. - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:47-50 for character width handling: verified impl->hashAndFlags & 4 correctly selects between unsigned char (8-bit) and char16_t (16-bit) buffers without signedness or truncation defects across Linux LP64 and Windows LLP64. - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:51-57 for index bounds safety: verified leading == impl->length handles all-space strings safely, and trailing termination at or before impl->length - leading - 1 guarantees impl->length - leading - trailing >= 1 with no unsigned underflow. - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp:56 for untrimmed preservation: verified !(leading | trailing) returns the input string directly to retain the existing StringImpl rather than allocating an identical copy. - Checked core/libs/prx/libSceNKWebKit/src/HtmlSpaceTrim.cpp and docs/dev/debt/libSceNKWebKit.md against AGENTS.md: confirmed no forbidden inline comments exist, upstream copyright notice matches maintainer precedent, and technical debt entry is properly recorded. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Looks Good To Me
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!18797
No description provided.