Bug 225282 - Invalid media query keyword values should not be parsable
Summary: Invalid media query keyword values should not be parsable
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Tim Nguyen (:ntim)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-02 10:02 PDT by Tim Nguyen (:ntim)
Modified: 2021-05-05 14:48 PDT (History)
12 users (show)

See Also:


Attachments
Patch (9.37 KB, patch)
2021-05-05 11:22 PDT, Tim Nguyen (:ntim)
dino: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tim Nguyen (:ntim) 2021-05-02 10:02:42 PDT
Examples:

prefers-color-scheme: none
prefers-color-scheme: aghadshudfsjhdsfkjhdsfdsfa
prefers-color-scheme: visible
prefers-color-scheme: hidden
prefers-color-scheme: -webkit-sticky
prefers-color-scheme: cssisawesome

Ditto for prefers-contrast

WebKit all considers them as parsable... 

This shows up in our WPT failures (notably the none cases for prefers-contrast/prefers-color-scheme).

Example snippet to reproduce:

function query_is_css_parseable(query) {
  const style = document.createElement('style');
  style.type = 'text/css';
  document.head.appendChild(style);

  const sheet = style.sheet;
  try {
    sheet.insertRule("@media " + query + "{}", 0);
    return sheet.cssRules.length == 1 &&
        sheet.cssRules[0].media.mediaText != "not all";
  } finally {
    while (sheet.cssRules.length)
      sheet.deleteRule(0);
    style.remove();
  }
}

query_is_css_parseable("(prefers-color-scheme: -webkit-sticky)") // should return false
Comment 1 Tim Nguyen (:ntim) 2021-05-05 11:22:07 PDT
Created attachment 427783 [details]
Patch
Comment 2 Radar WebKit Bug Importer 2021-05-05 11:22:36 PDT
<rdar://problem/77566627>
Comment 3 Dean Jackson 2021-05-05 11:31:26 PDT
In the future we might want to do this with generated code, the way we do with properties.
Comment 4 Tim Nguyen (:ntim) 2021-05-05 13:41:54 PDT
Committed r277039 (237352@main): <https://commits.webkit.org/237352@main>