<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>262146</bug_id>
          
          <creation_ts>2023-09-26 15:10:25 -0700</creation_ts>
          <short_desc>Parse &apos;systemLanguage&apos; as a comma separated list</short_desc>
          <delta_ts>2026-04-17 08:03:21 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>SVG</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=262140</see_also>
    
    <see_also>https://github.com/web-platform-tests/wpt/pull/59317</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, GoodFirstBug, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ahmad Saleem">ahmad.saleem792</reporter>
          <assigned_to name="Karl Dubost">karlcow</assigned_to>
          <cc>karlcow</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zimmermann</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1980312</commentid>
    <comment_count>0</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2023-09-26 15:10:25 -0700</bug_when>
    <thetext>Hi Team,

Going through another bug, I came across another failing test:

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

^ Fails in Safari / WebKit ToT while passes Chrome Canary 119 and Firefox Nightly 120.

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

Just wanted to raise, so we can fix it as well.

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980409</commentid>
    <comment_count>1</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-09-27 00:30:49 -0700</bug_when>
    <thetext>Hmm, Where could it fail?


systemLanguage is parsed as a SVGStringList
https://searchfox.org/wubkat/rev/42dc4893aca2f5a0e36c4314c8aa0555ebce6c88/Source/WebCore/svg/SVGTests.h#38-51

    SVGStringList&amp; systemLanguage() { return m_systemLanguage; }


And SVGStringList.parse
https://searchfox.org/wubkat/rev/42dc4893aca2f5a0e36c4314c8aa0555ebce6c88/Source/WebCore/svg/SVGStringList.h#47


And SVGStringList::parse(StringView data, UChar delimiter)
https://searchfox.org/wubkat/rev/42dc4893aca2f5a0e36c4314c8aa0555ebce6c88/Source/WebCore/svg/SVGStringList.cpp#34-64


but reset defines the parse(string, &apos; &apos;);
Only with space? is it because of this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980416</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-09-27 00:50:53 -0700</bug_when>
    <thetext>data:text/html,&lt;svg&gt;&lt;text systemLanguage=&quot;en-US, zh-Hans,zh-Hant&quot;&gt;&lt;/text&gt;&lt;/svg&gt;

document.querySelector(&apos;text&apos;).systemLanguage
returns an SVGStringList with indeed

* en-US,
* zh-Hans,zh-Hant


even  with a simpler test
data:text/html,&lt;svg&gt;&lt;text systemLanguage=&quot;en,fr,de&quot;&gt;&lt;/text&gt;&lt;/svg&gt;

it returns
* en,fr,de


That&apos;s bad indeed. I never gets it right


&quot;en,fr,de&quot;   -&gt; { 0: &quot;en,fr,de&quot; }
&quot;en, ,de&quot;    -&gt; { 0: &quot;en,&quot;, 1: &quot;,de&quot; }
&quot;en,,de&quot;     -&gt; { 0: &quot;en,,de&quot; }
&quot;en,,de&quot;     -&gt; { 0: &quot;en,,de&quot; }
&quot;en, fr, de&quot; -&gt; { 0: &quot;en,&quot;, 1: &quot;fr,&quot;, 3: &quot;de&quot; }

It separates on space, and never removes the comma. 

What does the spec says?
https://www.w3.org/TR/SVG2/struct.html#ConditionalProcessingSystemLanguageAttribute


Name:    systemLanguage	
Value:   set of comma-separated tokens [HTML]	
Initial: (none)	


defined in https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#set-of-comma-separated-tokens


A set of comma-separated tokens is a string containing zero or more tokens each separated from the next by a single U+002C COMMA character (,), where tokens consist of any string of zero or more characters, neither beginning nor ending with ASCII whitespace, nor containing any U+002C COMMA characters (,), and optionally surrounded by ASCII whitespace.

For instance, the string &quot; a ,b,,d d &quot; consists of four tokens: &quot;a&quot;, &quot;b&quot;, the empty string, and &quot;d d&quot;. Leading and trailing whitespace around each token doesn&apos;t count as part of the token, and the empty string can be a token.


The confusion comes probably from when it was written because 
requiredExtensions is a **space** separated attribute.
https://www.w3.org/TR/SVG2/struct.html#ConditionalProcessingRequiredExtensionsAttribute</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1980418</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2023-09-27 00:59:01 -0700</bug_when>
    <thetext>
And this is the interface for SVGStringList
https://www.w3.org/TR/SVG2/types.html#InterfaceSVGStringList</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1982248</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-10-03 15:11:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/116427520&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2069875</commentid>
    <comment_count>5</comment_count>
    <who name="">serakeri</who>
    <bug_when>2024-10-22 14:25:45 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/35582</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197969</commentid>
    <comment_count>6</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-08 06:42:28 -0700</bug_when>
    <thetext>This needs to be reworked a bit. There is basically not tests coverage. The previous tests are SVG 1.1 and some unrelated animation tests. 

SVGTests is the C++ class that implements the conditional processing attributes from the SVG spec: requiredExtensions and systemLanguage.
https://w3c.github.io/svgwg/svg2-draft/struct.html#ConditionalProcessing
https://searchfox.org/wubkat/source/Source/WebCore/svg/SVGTests.cpp

Any SVG element that can be conditionally shown or hidden (like elements inside a &lt;switch&gt;) mixes in SVGTests. It does two things:
   
1. Parses the attribute values from markup into an SVGStringList (the parseAttribute() method)
2. Evaluates whether the element should render, by checking if the listed languages/extensions match the user&apos;s environment (the isValid() method)

So when we write:

  &lt;switch&gt;
    &lt;text systemLanguage=&quot;fr&quot;&gt;Bonjour&lt;/text&gt;
    &lt;text systemLanguage=&quot;en&quot;&gt;Hello&lt;/text&gt;
    &lt;text&gt;Fallback&lt;/text&gt;
  &lt;/switch&gt;

There are WPT tests for SVG switch but probably not enough. This could be for another bug.
https://wpt.fyi/results/svg/animations
https://wpt.fyi/results/svg/struct/reftests/use-switch.svg

SVGTests::isValid() is what decides which &lt;text&gt; gets rendered — it reads the parsed tokens from systemLanguage and compares them against the browser&apos;s language setting.


https://searchfox.org/wubkat/rev/9971986dcebbc9ad5713a058e7951288c455bbee/Source/WebCore/svg/SVGTests.cpp#91-103
```cpp
void SVGTests::parseAttribute(const QualifiedName&amp; attributeName, const AtomString&amp; value)
{
    switch (attributeName.nodeName()) {
    case AttributeNames::requiredExtensionsAttr:
        protect(requiredExtensions())-&gt;reset(value);
        break;
    case AttributeNames::systemLanguageAttr:
        protect(systemLanguage())-&gt;reset(value);
        break;
    default:
        break;
    }
}
```

This method is called by the SVG element when the HTML parser (or setAttribute() from JavaScript) encounters a requiredExtensions or systemLanguage attribute. The value parameter is the raw attribute string, e.g. &quot;en, fr, de&quot;.

Step by step:

1. attributeName.nodeName()
    identifies which attribute we&apos;re dealing with. The switch dispatches to the right handler.
2. systemLanguage()
    returns a reference to the SVGStringList object that stores the parsed tokens for this element&apos;s systemLanguage attribute. It&apos;s a list of strings, like a Vector&lt;String&gt;.
3. protect(...)
    wraps the reference in a Ref smart pointer to keep it alive during the call (SaferCPP pattern — the object could theoretically be destroyed mid-operation if something re-entrant happens).
4. -&gt;reset(value)
    this is the key part. It clears the list and re-parses the raw string into tokens. Currently reset() calls parse(string, &apos; &apos;) — splitting on spaces. That&apos;s the bug. For systemLanguage, it should split on commas.

So the entire flow is: 
raw string &quot;en, fr, de&quot; 
→ reset() 
→ parse(string, &apos; &apos;) 
→ tokens [&quot;en,&quot;, &quot;fr,&quot;, &quot;de&quot;] (wrong). 

If we change to parse(string, &apos;,&apos;) 
→ tokens [&quot;en&quot;, &quot;fr&quot;, &quot;de&quot;] (correct).

We need WPT tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197979</commentid>
    <comment_count>7</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-08 07:46:30 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/62274</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2197986</commentid>
    <comment_count>8</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-08 08:08:51 -0700</bug_when>
    <thetext>This is fixing the parsing.
The validation will be fixed in https://bugs.webkit.org/show_bug.cgi?id=262140</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2201438</commentid>
    <comment_count>9</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-04-17 03:04:25 -0700</bug_when>
    <thetext>Committed 311439@main (94ce6308f502): &lt;https://commits.webkit.org/311439@main&gt;

Reviewed commits have been landed. Closing PR #62274 and removing active labels.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2201508</commentid>
    <comment_count>10</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2026-04-17 08:03:21 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/59317</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>