Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: e94c2e91e23993244d6ba54a60f6e2233d4a21df
      
https://github.com/WebKit/WebKit/commit/e94c2e91e23993244d6ba54a60f6e2233d4a21df
  Author: Chris Dumez <[email protected]>
  Date:   2026-04-04 (Sat, 04 Apr 2026)

  Changed paths:
    M Source/WTF/wtf/text/StringImpl.cpp
    M Source/WTF/wtf/text/StringView.h
    M Source/WebCore/css/CSSMarkup.cpp
    M Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp
    M Tools/TestWebKitAPI/Tests/WTF/StringView.cpp

  Log Message:
  -----------
  StringImpl::characterStartingAt should return lone surrogates instead of 0
https://bugs.webkit.org/show_bug.cgi?id=311463

Reviewed by Anne van Kesteren.

Previously, characterStartingAt() returned 0 for lone surrogates, making
them indistinguishable from U+0000 (NUL). Return the raw surrogate code
unit value instead.

Also add the same function to StringView because I will need it for my
next two PRs, and add API test coverage for both StringImpl and
StringView.

Reviewed all call sites:
  - CSSMarkup.cpp (serializeIdentifier): Remove workaround that re-fetched
    the raw code unit via operator[] when characterStartingAt returned 0.

  - CSSMarkup.cpp (serializeString): Previously a lone surrogate returned 0
    which matched c <= 0x1f and was serialized as \0. Now the surrogate value
    (>= 0xD800) falls through to appendTo.append(c), which is more correct.

  - URLHelpers.cpp: Passes results to isLookalikeCharacter() and
    U16_LENGTH(). A lone surrogate won't be a lookalike, and U16_LENGTH on a
    BMP-range surrogate value correctly returns 1. No issue.

  - EventHandler.cpp: Checks !U_IS_BMP(c). Lone surrogates (0xD800-0xDFFF)
    are in the BMP range, so U_IS_BMP returns true, same as for 0.

  - KeyboardScrollingAnimator.cpp: Compares against ' '. A lone surrogate
    won't match, same as 0.

  - RenderTreeBuilderFirstLetter.cpp: Passes result to
    shouldSkipForFirstLetter() and isPunctuationForFirstLetter(). A lone
    surrogate won't match any of those conditions.

  - KeyboardEvent.cpp: Returns the value as a charCode. Returning the actual
    surrogate value is more correct than returning 0.

* Source/WTF/wtf/text/StringImpl.cpp:
(WTF::StringImpl::characterStartingAt):
* Source/WTF/wtf/text/StringView.h:
(WTF::StringView::characterStartingAt):
* Source/WebCore/css/CSSMarkup.cpp:
(WebCore::serializeIdentifier):
* Tools/TestWebKitAPI/Tests/WTF/StringImpl.cpp:
* Tools/TestWebKitAPI/Tests/WTF/StringView.cpp:

Canonical link: https://commits.webkit.org/310568@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to