Bug 225282

Summary: Invalid media query keyword values should not be parsable
Product: WebKit Reporter: Tim Nguyen (:ntim) <ntim>
Component: CSSAssignee: Tim Nguyen (:ntim) <ntim>
Status: RESOLVED FIXED    
Severity: Normal CC: dino, eric.carlson, esprehn+autocc, ews-watchlist, glenn, gyuyoung.kim, jer.noble, macpherson, menard, philipj, sergio, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch dino: review+, ews-feeder: commit-queue-

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>