Bug 267193 - SVGLength*.valueAsString should accept/serialize all valid lengths
Summary: SVGLength*.valueAsString should accept/serialize all valid lengths
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2024-01-06 19:09 PST by Ahmad Saleem
Modified: 2024-02-02 06:09 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2024-01-06 19:09:59 PST
Hi Team,

While looking into 'SVGLength', I stumbled across another failing tests from Blink Commit.

Blink Commit: https://chromium.googlesource.com/chromium/src.git/+/c686b61c567b5d3be546a4e228912141155a25ca

Test Case: https://jsfiddle.net/ucswaop3/show

^ Safari fails (even WebKit ToT) following:

> Test unit types that don't have a corresponding IDL constant

Both Chrome Canary 122 and Firefox Nightly 123 pass this test so marking this as 'BrowserCompat'.

___

Web-Spec: https://svgwg.org/svg2-draft/types.html#__svg__SVGLength__valueAsString

Chrome / Blink bug title > should not throw (setter) or return "0" on "new" units.

__

Although reading 'web-spec', it also expect 'emptyString', while we return nothing:

https://searchfox.org/wubkat/source/Source/WebCore/svg/SVGLengthValue.cpp#326

ExceptionOr<void> SVGLengthValue::setValueAsString(StringView string)
{
    if (string.isEmpty())
        return { };

__

Should we remove this also?

__

Just wanted to raise to get input and also fix failing test case.

Thanks!
Comment 2 Radar WebKit Bug Importer 2024-01-13 19:10:15 PST
<rdar://problem/120959223>
Comment 3 Ahmad Saleem 2024-02-02 06:09:06 PST
We get `SyntaxError` on failing this test case, so it could be:

ExceptionOr<void> SVGLengthValue::setValueAsString(StringView string)
{
    if (string.isEmpty())
        return { };

    return readCharactersForParsing(string, [&](auto buffer) -> ExceptionOr<void> {
        auto convertedNumber = parseNumber(buffer, SuffixSkippingPolicy::DontSkip);
        if (!convertedNumber)
            return Exception { ExceptionCode::SyntaxError };

        auto lengthType = parseLengthType(buffer);
        if (lengthType == SVGLengthType::Unknown)
            return Exception { ExceptionCode::SyntaxError };

        m_lengthType = lengthType;
        m_valueInSpecifiedUnits = *convertedNumber;
        return { };
    });
}

__

In both above `SyntaxError` area.