Bug 165097 - insertRule() throws CSS SYNTAX_ERR exception if no CSS declarations are included
Summary: insertRule() throws CSS SYNTAX_ERR exception if no CSS declarations are included
Status: RESOLVED UNMAINTAINED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml (other bugs)
Version First Reported In: unspecified
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-27 12:05 UTC by Conrad Irwin
Modified: 2024-05-06 18:38 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Conrad Irwin 2008-06-27 12:05:15 UTC
Version:           3.5.9 (using KDE 3.5.9)
Installed from:    Debian testing/unstable Packages
Compiler:          gcc version 4.3.1 (Debian 4.3.1-2)   Configured with: ../src/configure -v --with-pkgversion='Debian 4.3.1-2' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --enable-targets=all --enable-cld --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu 
OS:                Linux

In the test case below, the alert('done') does not occur due to a javascript crash of some sort. Although the insertRule is useless with a blank rule body, it shouldn't die completely.

Including a comment between the {/*comme ca*/} also fails, as does an {;}, so I assume it is just if there isn't a valid rule there.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
 <head>
  <title>insertRule test</title>
  <style type="text/css">/*empty stylesheet*/</style>
 </head>
 <!-- <body onload="document.styleSheets[0].insertRule('body {font-weight: bold;}',0);alert('done');"> -->
 <body onload="document.styleSheets[0].insertRule('body {}',0);alert('done');">-->
  Minimal test
</html>
Comment 1 Maksim Orlovich 2008-06-27 14:47:14 UTC
A bunch of things wrong here here:

1) ruleset: parsing returns 0 for {}, not an empty CSSStyleRuleImpl.
I don't think that's correct CSS OM-wise, really.

2) We can't tell an empty parse from a parse error.
Of course, given the forward compat stuff, one would have to tell the recoverable errors from non-recoverable... Don't know about CSS parser enough to do it myself.

More detailed testcase, also shows a seeming IceWeasel 3 bug (which might not be a bug based on details of forward-compatible parsing rule):
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
 <html> 
  <head> 
   <title>insertRule test</title> 
   <style type="text/css">/*empty stylesheet*/</style> 
  </head> 
  <script>
  function tryAdd(css) {
      try {
          document.styleSheets[0].insertRule(css, 0);
          alert("Add of " + css + " ok, length now:" + document.styleSheets[0].cssRules.length);
      } catch (e) {
          alert("Add of " + css + " failed with exception:" + e);
      }
  }
  
  function test() {
    tryAdd("body {font-weight: bold; }");
    tryAdd("body {}");
    tryAdd("xyz");
    tryAdd("{");
    tryAdd("foo{");
    tryAdd("@export");
  }
  </script>
  <body onload="test()">
   Minimal test 
 </html> 
 
Comment 2 Justin Zobel 2021-03-21 00:25:06 UTC
Thank you for the bug report.

As this report hasn't seen any changes in 10 years or more, we ask if you can please confirm that the issue still persists.

If this bug is no longer persisting or relevant please change the status to resolved.
Comment 3 Christoph Cullmann 2024-05-06 18:38:10 UTC
Dear user,

KHTML (and KJS) was a long time more or less unmaintained and got removed in KF6.

Please migrate to use a QWebEngine based HTML component.

We will do no further fixes or improvements to the KF5 branches of these components beside important security fixes.

For security issues, please see:

https://kde.org/info/security/

Sorry that we did not fix this issue during the life-time of KHTML.

Greetings
Christoph Cullmann