<?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>210595</bug_id>
          
          <creation_ts>2020-04-16 01:15:15 -0700</creation_ts>
          <short_desc>The &lt;style&gt; element should not convert \n into &lt;br&gt;</short_desc>
          <delta_ts>2023-08-26 00:31:25 -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>HTML Editing</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Milan Crha">mcrha</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>bugs-noreply</cc>
    
    <cc>cdumez</cc>
    
    <cc>cgarcia</cc>
    
    <cc>esprehn+autocc</cc>
    
    <cc>ews-watchlist</cc>
    
    <cc>gyuyoung.kim</cc>
    
    <cc>wenson_hsieh</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1642175</commentid>
    <comment_count>0</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-16 01:15:15 -0700</bug_when>
    <thetext>The &lt;style&gt; element inside &lt;head&gt; can use \n as a separator between CSS rules (yes, they should be in a comment, but it&apos;s still possible to write them as regular text inside the element). When I want to get the content of the HTML document the \n are converted into &lt;br&gt; tags, which can lead to broken CSS rules when this HTML is loaded back. This conversion happens when setting style.innerText value.

Steps:
a) open the MiniBrowser and there the Inspector
b) run in the Inspector Console:

   document.documentElement.innerHTML = &quot;&lt;head&gt;&lt;style&gt; body {color:orange;}\nbody {background:blue;}&lt;/style&gt;&lt;/head&gt;&lt;body&gt;text&lt;/body&gt;&quot;

   * you see a blue document with orange &apos;text&apos; at the top, as expected.
   * the &apos;Elements&apos; tab shows the &lt;style&gt; element content as one long line, as expected.

c) run in the Inspector Console:

   document.head.firstElementChild.innerText = &quot;body {color:green;}\nbody {background:red;}&quot;

   * you see a red document with green &apos;text&apos; at the top, as expected.
   * the &apos;Elements&apos; tab shows the &lt;style&gt; element content with &lt;br&gt; element, where \n was used, which is wrong.

d) run in the Inspector Console:

   document.documentElement.innerHTML = document.documentElement.innerHTML

   * you see a white document with green &apos;text&apos; at the top, which is wrong.
   * the &apos;Elements&apos; tab shows the &lt;style&gt; element content with &lt;br&gt; as a regular text, not as an element, which is wrong.

The expected is that:
* after c) the &lt;style&gt;&apos;s content will not contain &lt;br&gt; element
* after d) there will be absolutely no change in the view, neither in the HTML content/structure

This is with the trunk at r259630.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1642178</commentid>
    <comment_count>1</comment_count>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-16 01:32:18 -0700</bug_when>
    <thetext>It seems I can workaround this by using style.innerHTML instead of style.innerText, but I&apos;m afraid it would have some side effects when the content has &gt;, &lt;, &amp; or some such characters.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1642187</commentid>
    <comment_count>2</comment_count>
      <attachid>396630</attachid>
    <who name="Milan Crha">mcrha</who>
    <bug_when>2020-04-16 02:45:26 -0700</bug_when>
    <thetext>Created attachment 396630
proposed patch

This helps, though I&apos;m not sure whether it&apos;s the way you&apos;d like to have it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1973754</commentid>
    <comment_count>3</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-08-26 00:31:25 -0700</bug_when>
    <thetext>This is how innerText and innerHTML are supposed to behave. Firefox does the exact same thing.

See https://html.spec.whatwg.org/#the-innertext-idl-attribute.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>396630</attachid>
            <date>2020-04-16 02:45:26 -0700</date>
            <delta_ts>2020-04-16 02:45:26 -0700</delta_ts>
            <desc>proposed patch</desc>
            <filename>wk.patch</filename>
            <type>text/plain</type>
            <size>1775</size>
            <attacher name="Milan Crha">mcrha</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJDb3JlL0No
YW5nZUxvZwppbmRleCA1M2NjNTY4MjUxZS4uYzc2N2YyMWUwZjIgMTAwNjQ0Ci0tLSBhL1NvdXJj
ZS9XZWJDb3JlL0NoYW5nZUxvZworKysgYi9Tb3VyY2UvV2ViQ29yZS9DaGFuZ2VMb2cKQEAgLTEs
MyArMSwxNCBAQAorMjAyMC0wNC0xNiAgTWlsYW4gQ3JoYSAgPG1jcmhhQHJlZGhhdC5jb20+CisK
KyAgICAgICAgW0dUS10gVGhlIDxzdHlsZT4gZWxlbWVudCBzaG91bGQgbm90IGNvbnZlcnQgXG4g
aW50byA8YnI+CisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9p
ZD0yMTA1OTUKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMhKS4KKworICAgICAg
ICAqIGh0bWwvSFRNTEVsZW1lbnQuY3BwOgorICAgICAgICAoV2ViQ29yZTo6SFRNTEVsZW1lbnQ6
OnNldElubmVyVGV4dCk6IERvIG5vdCBjb252ZXJ0IG5ldyBsaW5lcworICAgICAgICB0byA8QlI+
IGVsZW1lbnRzIGluIDxTVFlMRT4gZWxlbWVudC4KKwogMjAyMC0wNC0wNyAgRG91ZyBLZ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IHRleHRhcmVhIGVsZW1lbnRzIHRoYXQgYXJl
IGRpc3BsYXk6bm9uZT8KICAgICBhdXRvKiByID0gcmVuZGVyZXIoKTsKLSAgICBpZiAoKHIgJiYg
ci0+c3R5bGUoKS5wcmVzZXJ2ZU5ld2xpbmUoKSkgfHwgKGlzQ29ubmVjdGVkKCkgJiYgaXNUZXh0
Q29udHJvbElubmVyVGV4dEVsZW1lbnQoKSkpIHsKKyAgICBpZiAoKHIgJiYgci0+c3R5bGUoKS5w
cmVzZXJ2ZU5ld2xpbmUoKSkgfHwgKGlzQ29ubmVjdGVkKCkgJiYgaXNUZXh0Q29udHJvbElubmVy
VGV4dEVsZW1lbnQoKSkgfHwgKGlzPEhUTUxTdHlsZUVsZW1lbnQ+KCp0aGlzKSkpIHsKICAgICAg
ICAgaWYgKCF0ZXh0LmNvbnRhaW5zKCdccicpKSB7CiAgICAgICAgICAgICByZXBsYWNlQWxsQ2hp
bGRyZW4oZG9jdW1lbnQoKS5jcmVhdGVUZXh0Tm9kZSh0ZXh0KSk7CiAgICAgICAgICAgICByZXR1
cm4geyB9Owo=
</data>
<flag name="review"
          id="412039"
          type_id="1"
          status="?"
          setter="mcrha"
    />
    <flag name="commit-queue"
          id="412040"
          type_id="3"
          status="?"
          setter="mcrha"
    />
          </attachment>
      

    </bug>

</bugzilla>