<?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>240566</bug_id>
          
          <creation_ts>2022-05-18 01:41:29 -0700</creation_ts>
          <short_desc>innerText from element with &quot;white-space: pre-line&quot; incorrectly removes line breaks</short_desc>
          <delta_ts>2025-03-11 22:04:44 -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>DOM</component>
          <version>Safari 15</version>
          <rep_platform>All</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar, WPTImpact</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>289597</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter>ik</reporter>
          <assigned_to name="Chris Dumez">cdumez</assigned_to>
          <cc>ahmad.saleem792</cc>
    
    <cc>cdumez</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1869943</commentid>
    <comment_count>0</comment_count>
      <attachid>459530</attachid>
    <who name="">ik</who>
    <bug_when>2022-05-18 01:41:29 -0700</bug_when>
    <thetext>Created attachment 459530
Testcase v101

When I retrieve the innerText value of an element that has &quot;white-space: pre-line;&quot;, the resulting string does not contain any line breaks (\n).

The following changes/variations do preserve line breaks when retrieving :

* Retrieving textContent instead of innerText
* Using &quot;pre-wrap&quot;
* A combination of the above

... but these have side-effects, as it causes slightly different behavior.

According to MDN, newlines should be preserved for both pre-line and pre-wrap:
https://developer.mozilla.org/en-US/docs/Web/CSS/white-space#values

See attached testcase, also available here:
https://testcase.rejh.nl/webkit-pre-line-innertext/

* The first div has &quot;white-space: pre-line&quot;
* The second div has &quot;pre-wrap&quot;
* Use the buttons to print innerText or textContent to the console

Note: I&apos;ve tested this in Safari, Chrome and Firefox. Only Chrome returns the same result for innerText and textContent when &quot;pre-line&quot; is set, preserving line breaks. Firefox seems to also strip the newline characters when retrieving innerText while preserving them for textContent. If the intended/spec&apos;d behavior of innerText is to remove line breaks for &quot;pre-line&quot;, I&apos;ll happily file a bug @ Chrome :)

Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1870049</commentid>
    <comment_count>1</comment_count>
    <who name="Sam Sneddon [:gsnedders]">gsnedders</who>
    <bug_when>2022-05-18 10:06:43 -0700</bug_when>
    <thetext>https://html.spec.whatwg.org/multipage/dom.html#rendered-text-collection-steps says:

&gt; If node is a Text node, then for each CSS text box produced by node, in content order, compute the text of the box after application of the CSS &apos;white-space&apos; processing rules and &apos;text-transform&apos; rules, set items to the list of the resulting strings, and return items. The CSS &apos;white-space&apos; processing rules are slightly modified: collapsible spaces at the end of lines are always collapsed, but they are only removed if the line is the last line of the block, or it ends with a br element. Soft hyphens should be preserved. [CSSTEXT]

This implies that pre-line should be preserve the new lines.

Not looked closely at Firefox, but it seems Safari is the only browser failing the &apos;\n preserved (&quot;&lt;div style=&apos;white-space:pre-line&apos;&gt;abc\ndef&quot;)&apos; subtest at https://wpt.fyi/results/html/dom/elements/the-innertext-and-outertext-properties/getter.html?label=master&amp;label=experimental&amp;product=chrome&amp;product=firefox&amp;product=safari&amp;aligned</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1870085</commentid>
    <comment_count>2</comment_count>
    <who name="Chris Dumez">cdumez</who>
    <bug_when>2022-05-18 11:41:56 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/738</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1871683</commentid>
    <comment_count>3</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-05-25 01:42:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/93887979&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1919253</commentid>
    <comment_count>4</comment_count>
    <who name="">ik</who>
    <bug_when>2022-12-14 12:21:49 -0800</bug_when>
    <thetext>Any news on this? A pull request was filed but nothing since?</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>459530</attachid>
            <date>2022-05-18 01:41:29 -0700</date>
            <delta_ts>2022-05-18 01:41:29 -0700</delta_ts>
            <desc>Testcase v101</desc>
            <filename>webkit-pre-line-innertext-v101.zip</filename>
            <type>application/x-zip-compressed</type>
            <size>1225</size>
            <attacher>ik</attacher>
            
              <data encoding="base64">UEsDBBQAAAAAAJRQslQAAAAAAAAAAAAAAAAaAAAAd2Via2l0LXByZS1saW5lLWlubmVydGV4dC9Q
SwMEFAAAAAgATVOyVJRNuB1XAwAA3QoAACQAAAB3ZWJraXQtcHJlLWxpbmUtaW5uZXJ0ZXh0L2lu
ZGV4Lmh0bWzdVktv1DAQvu+vMOGwXWmzppQDSpNcShEHKIgtQkiVkDee3Vh1bGM7uy2I/87YyT7a
rYDyOtDDZjKPz9+MZybNHzx7fXL+4c0pqX0jy0EeHkQytSgSUEk5QA0wXg4IyRvwjFQ1sw58kbw7
f54+TbYGxRookqWAldHWJ6TSyoNCx5Xgvi44LEUFaXwZE6GEF0ymrmISisPJow7ICy+hfA+zS+HJ
TFsONp3pKxKjaA1iUXtqGOdCLXLaeQ9CoPPXvUgwjl+TLyiGvzmySOesEfI6I44plzqwYn4czV+7
gImxkEqhYNyJK8vMmHg2k7DBaZhdCJWRp+bquFf1PHZ1PeeMHJor4rQUnDw8Ojq6aU0t46J1GXkS
4/Z5bE9d1cJD6gyrICNrax8Tfrd87w5ZW3eP2SS2AxOuxHPU3cjsNsOcbsucu8oK48tonbeq8kIr
oltvWn+wZLKF0RoudALWAiZSLw6Gb9mKRHs2HHfC6Pguv1NsDQN84zWxYCQmdUAvFF2MyfDiQg1H
fezXyG5NKaddyw7y0Arhaco3ffFyatCBiyWpJHOuSNZVxQZ8GUr/8LB/Ph70whMExAAMm7XehyxV
JUV1WSR9ulxXbYOtPvnUgr2egoTKa3sw3NzncDQRSoE9hys/SsqNnNMO8fegPSKdxGEL4Nu3DXxf
gb4X9ivQG/77CuSM1BbmRVJ7b1xGKe4kkNqAnTT6s5CSTbRdUFDpuynFcx3FTURPplO6M1QPYze6
BMfILsIe/DjDbXmZEAuySJRGOMwtKV89O8t2hzGnrAylD0TOa8DFJKVe4ZT18+jaBneM+AyOeDTP
oGZLoS3R8/i+RJtu3S4i6ZhkHWpEWV+p80xxZnkatf1uXe/xINtOiGqkhT8772ewIqGy7rZhisci
P8QOpPfM4UJJ6CSDad02niqe6nm33lzE+Z6HRrY2+qE3GGYZXvpOBEqYQnxuPk8+TPvdCVaaQ6m0
bZjMaXy5eTgvTzRev3GAev4z+veY5m3dW2j0cs/zBX5Lg25L/LscQ/3+EMczTVZ/hybO3t0cw5bB
D2wH/zP6nuMvu/+YaNxtf4htd+v7hfvdYoamv29F/3Fnziywy7Sb3HsyvU81f6zbjn4/8CiELRd2
PF1run9mvwFQSwECPwAUAAAAAACUULJUAAAAAAAAAAAAAAAAGgAkAAAAAAAAABAAAAAAAAAAd2Vi
a2l0LXByZS1saW5lLWlubmVydGV4dC8KACAAAAAAAAEAGAA7ABrsjWrYAU/hSzOPatgBFFGn6Y1q
2AFQSwECPwAUAAAACABNU7JUlE24HVcDAADdCgAAJAAkAAAAAAAAACAAAAA4AAAAd2Via2l0LXBy
ZS1saW5lLWlubmVydGV4dC9pbmRleC5odG1sCgAgAAAAAAABABgABToD95Bq2AEM5NT4kGrYATsA
GuyNatgBUEsFBgAAAAACAAIA4gAAANEDAAAAAA==
</data>

          </attachment>
      

    </bug>

</bugzilla>