Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(507)

Side by Side Diff: Source/core/css/parser/MediaQueryParser.cpp

Issue 867363002: Some invalid media queries are parsed as valid (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a test Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/parser/MediaQueryParser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/css/parser/MediaQueryParser.h" 6 #include "core/css/parser/MediaQueryParser.h"
7 7
8 #include "core/MediaTypeNames.h" 8 #include "core/MediaTypeNames.h"
9 #include "core/css/parser/CSSPropertyParser.h" 9 #include "core/css/parser/CSSPropertyParser.h"
10 #include "core/css/parser/CSSTokenizer.h" 10 #include "core/css/parser/CSSTokenizer.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 { 72 {
73 if (type == IdentToken && equalIgnoringCase(token.value(), "not")) 73 if (type == IdentToken && equalIgnoringCase(token.value(), "not"))
74 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not); 74 setStateAndRestrict(ReadFeatureStart, MediaQuery::Not);
75 else 75 else
76 readFeatureStart(type, token); 76 readFeatureStart(type, token);
77 } 77 }
78 78
79 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok en& token) 79 void MediaQueryParser::readMediaType(CSSParserTokenType type, const CSSParserTok en& token)
80 { 80 {
81 if (type == LeftParenthesisToken) { 81 if (type == LeftParenthesisToken) {
82 m_state = ReadFeature; 82 if (m_mediaQueryData.restrictor() != MediaQuery::None)
83 m_state = SkipUntilComma;
84 else
85 m_state = ReadFeature;
83 } else if (type == IdentToken) { 86 } else if (type == IdentToken) {
84 if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "not") ) { 87 if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "not") ) {
85 setStateAndRestrict(ReadMediaType, MediaQuery::Not); 88 setStateAndRestrict(ReadMediaType, MediaQuery::Not);
86 } else if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "only")) { 89 } else if (m_state == ReadRestrictor && equalIgnoringCase(token.value(), "only")) {
87 setStateAndRestrict(ReadMediaType, MediaQuery::Only); 90 setStateAndRestrict(ReadMediaType, MediaQuery::Only);
88 } else { 91 } else {
Yoav Weiss 2015/01/30 08:31:51 Nit: Can you make that an "else if"?
89 m_mediaQueryData.setMediaType(token.value()); 92 if (m_mediaQueryData.restrictor() != MediaQuery::None && (equalIgnor ingCase(token.value(), "not")
90 m_state = ReadAnd; 93 || equalIgnoringCase(token.value(), "and")
94 || equalIgnoringCase(token.value(), "or")
95 || equalIgnoringCase(token.value(), "only"))) {
Yoav Weiss 2015/01/30 08:31:51 Can you break out the "equqlIgnoringCase"s into th
96 m_state = SkipUntilComma;
97 } else {
98 m_mediaQueryData.setMediaType(token.value());
99 m_state = ReadAnd;
100 }
91 } 101 }
92 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state != ReadRestrictor)) { 102 } else if (type == EOFToken && (!m_querySet->queryVector().size() || m_state != ReadRestrictor)) {
93 m_state = Done; 103 m_state = Done;
94 } else { 104 } else {
95 m_state = SkipUntilComma; 105 m_state = SkipUntilComma;
96 if (type == CommaToken) 106 if (type == CommaToken)
97 skipUntilComma(type, token); 107 skipUntilComma(type, token);
98 } 108 }
99 } 109 }
100 110
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return true; 290 return true;
281 } 291 }
282 292
283 void MediaQueryData::setMediaType(const String& mediaType) 293 void MediaQueryData::setMediaType(const String& mediaType)
284 { 294 {
285 m_mediaType = mediaType; 295 m_mediaType = mediaType;
286 m_mediaTypeSet = true; 296 m_mediaTypeSet = true;
287 } 297 }
288 298
289 } // namespace blink 299 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/MediaQueryParser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698