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

Side by Side Diff: Source/core/css/CSSGrammar.y

Issue 320783002: CSSGrammer.y should not allow missing closing bracket when it parses querySelector's selector text. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « LayoutTests/fast/css/parsing-unexpected-eof.html ('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 %{ 1 %{
2 2
3 /* 3 /*
4 * Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org) 4 * Copyright (C) 2002-2003 Lars Knoll (knoll@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 App le Inc. All rights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 App le Inc. All rights reserved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com) 6 * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
7 * Copyright (C) 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2012 Intel Corporation. All rights reserved. 8 * Copyright (C) 2012 Intel Corporation. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 %type <rule> rule 281 %type <rule> rule
282 %type <rule> valid_rule 282 %type <rule> valid_rule
283 %type <ruleList> block_rule_body 283 %type <ruleList> block_rule_body
284 %type <ruleList> block_rule_list 284 %type <ruleList> block_rule_list
285 %type <rule> block_rule 285 %type <rule> block_rule
286 %type <rule> block_valid_rule 286 %type <rule> block_valid_rule
287 %type <rule> supports 287 %type <rule> supports
288 %type <rule> viewport 288 %type <rule> viewport
289 %type <boolean> keyframes_rule_start 289 %type <boolean> keyframes_rule_start
290 290
291 %type <boolean> closing_square_bracket
292 %type <boolean> closing_parenthesis
291 %type <string> maybe_ns_prefix 293 %type <string> maybe_ns_prefix
292 294
293 %type <string> namespace_selector 295 %type <string> namespace_selector
294 296
295 %type <string> string_or_uri 297 %type <string> string_or_uri
296 %type <string> ident_or_string 298 %type <string> ident_or_string
297 %type <string> medium 299 %type <string> medium
298 %type <marginBox> margin_sym 300 %type <marginBox> margin_sym
299 301
300 %type <mediaList> media_list 302 %type <mediaList> media_list
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 | maybe_sgml SGML_CD 450 | maybe_sgml SGML_CD
449 | maybe_sgml WHITESPACE 451 | maybe_sgml WHITESPACE
450 ; 452 ;
451 453
452 closing_brace: 454 closing_brace:
453 '}' 455 '}'
454 | %prec LOWEST_PREC TOKEN_EOF 456 | %prec LOWEST_PREC TOKEN_EOF
455 ; 457 ;
456 458
457 closing_parenthesis: 459 closing_parenthesis:
458 ')' 460 ')' { $$ = true; }
459 | %prec LOWEST_PREC TOKEN_EOF 461 | %prec LOWEST_PREC TOKEN_EOF {
462 // While parsing query selector's selector text, we should not
463 // allow missing closing parenthesis.
464 $$ = !parser->m_selectorListForParseSelector;
465 }
460 ; 466 ;
461 467
462 closing_square_bracket: 468 closing_square_bracket:
463 ']' 469 ']' { $$ = true; }
464 | %prec LOWEST_PREC TOKEN_EOF 470 | %prec LOWEST_PREC TOKEN_EOF {
471 // While parsing query selector's selector text, we should not
472 // allow missing closing square bracket.
473 $$ = !parser->m_selectorListForParseSelector;
474 }
465 ; 475 ;
466 476
467 semi_or_eof: 477 semi_or_eof:
468 ';' 478 ';'
469 | TOKEN_EOF 479 | TOKEN_EOF
470 ; 480 ;
471 481
472 maybe_charset: 482 maybe_charset:
473 /* empty */ 483 /* empty */
474 | CHARSET_SYM maybe_space STRING maybe_space semi_or_eof { 484 | CHARSET_SYM maybe_space STRING maybe_space semi_or_eof {
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 attr_name: 1245 attr_name:
1236 IDENT maybe_space { 1246 IDENT maybe_space {
1237 if (parser->m_context.isHTMLDocument()) 1247 if (parser->m_context.isHTMLDocument())
1238 parser->tokenToLowerCase($1); 1248 parser->tokenToLowerCase($1);
1239 $$ = $1; 1249 $$ = $1;
1240 } 1250 }
1241 ; 1251 ;
1242 1252
1243 attrib: 1253 attrib:
1244 '[' maybe_space attr_name closing_square_bracket { 1254 '[' maybe_space attr_name closing_square_bracket {
1255 if (!$4)
1256 YYERROR;
1245 $$ = parser->createFloatingSelector(); 1257 $$ = parser->createFloatingSelector();
1246 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom)); 1258 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
1247 $$->setMatch(CSSSelector::Set); 1259 $$->setMatch(CSSSelector::Set);
1248 } 1260 }
1249 | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space cl osing_square_bracket { 1261 | '[' maybe_space attr_name match maybe_space ident_or_string maybe_space cl osing_square_bracket {
1262 if (!$8)
1263 YYERROR;
1250 $$ = parser->createFloatingSelector(); 1264 $$ = parser->createFloatingSelector();
1251 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom)); 1265 $$->setAttribute(QualifiedName(nullAtom, $3, nullAtom));
1252 $$->setMatch((CSSSelector::Match)$4); 1266 $$->setMatch((CSSSelector::Match)$4);
1253 $$->setValue($6); 1267 $$->setValue($6);
1254 } 1268 }
1255 | '[' maybe_space namespace_selector attr_name closing_square_bracket { 1269 | '[' maybe_space namespace_selector attr_name closing_square_bracket {
1270 if (!$5)
1271 YYERROR;
1256 $$ = parser->createFloatingSelector(); 1272 $$ = parser->createFloatingSelector();
1257 $$->setAttribute(parser->determineNameInNamespace($3, $4)); 1273 $$->setAttribute(parser->determineNameInNamespace($3, $4));
1258 $$->setMatch(CSSSelector::Set); 1274 $$->setMatch(CSSSelector::Set);
1259 } 1275 }
1260 | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_st ring maybe_space closing_square_bracket { 1276 | '[' maybe_space namespace_selector attr_name match maybe_space ident_or_st ring maybe_space closing_square_bracket {
1277 if (!$9)
1278 YYERROR;
1261 $$ = parser->createFloatingSelector(); 1279 $$ = parser->createFloatingSelector();
1262 $$->setAttribute(parser->determineNameInNamespace($3, $4)); 1280 $$->setAttribute(parser->determineNameInNamespace($3, $4));
1263 $$->setMatch((CSSSelector::Match)$5); 1281 $$->setMatch((CSSSelector::Match)$5);
1264 $$->setValue($7); 1282 $$->setValue($7);
1265 } 1283 }
1266 | '[' selector_recovery closing_square_bracket { 1284 | '[' selector_recovery closing_square_bracket {
1267 YYERROR; 1285 YYERROR;
1268 } 1286 }
1269 ; 1287 ;
1270 1288
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 $$->setValue($4); 1348 $$->setValue($4);
1331 // FIXME: This call is needed to force selector to compute the pseudoTyp e early enough. 1349 // FIXME: This call is needed to force selector to compute the pseudoTyp e early enough.
1332 CSSSelector::PseudoType type = $$->pseudoType(); 1350 CSSSelector::PseudoType type = $$->pseudoType();
1333 if (type == CSSSelector::PseudoUnknown) { 1351 if (type == CSSSelector::PseudoUnknown) {
1334 parser->reportError($3, InvalidSelectorPseudoCSSError); 1352 parser->reportError($3, InvalidSelectorPseudoCSSError);
1335 YYERROR; 1353 YYERROR;
1336 } 1354 }
1337 } 1355 }
1338 // used by ::cue(:past/:future) 1356 // used by ::cue(:past/:future)
1339 | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space closing_p arenthesis { 1357 | ':' ':' CUEFUNCTION maybe_space simple_selector_list maybe_space closing_p arenthesis {
1358 if (!$7)
1359 YYERROR;
1340 $$ = parser->createFloatingSelector(); 1360 $$ = parser->createFloatingSelector();
1341 $$->setMatch(CSSSelector::PseudoElement); 1361 $$->setMatch(CSSSelector::PseudoElement);
1342 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($5)); 1362 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($5));
1343 $$->setValue($3); 1363 $$->setValue($3);
1344 CSSSelector::PseudoType type = $$->pseudoType(); 1364 CSSSelector::PseudoType type = $$->pseudoType();
1345 if (type != CSSSelector::PseudoCue) 1365 if (type != CSSSelector::PseudoCue)
1346 YYERROR; 1366 YYERROR;
1347 } 1367 }
1348 | ':' ':' CUEFUNCTION selector_recovery closing_parenthesis { 1368 | ':' ':' CUEFUNCTION selector_recovery closing_parenthesis {
1349 YYERROR; 1369 YYERROR;
1350 } 1370 }
1351 // use by :-webkit-any. 1371 // use by :-webkit-any.
1352 // FIXME: should we support generic selectors here or just simple_selectors? 1372 // FIXME: should we support generic selectors here or just simple_selectors?
1353 // Use simple_selector_list for now to match -moz-any. 1373 // Use simple_selector_list for now to match -moz-any.
1354 // See http://lists.w3.org/Archives/Public/www-style/2010Sep/0566.html for s ome 1374 // See http://lists.w3.org/Archives/Public/www-style/2010Sep/0566.html for s ome
1355 // related discussion with respect to :not. 1375 // related discussion with respect to :not.
1356 | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space closing_paren thesis { 1376 | ':' ANYFUNCTION maybe_space simple_selector_list maybe_space closing_paren thesis {
1377 if (!$6)
1378 YYERROR;
1357 $$ = parser->createFloatingSelector(); 1379 $$ = parser->createFloatingSelector();
1358 $$->setMatch(CSSSelector::PseudoClass); 1380 $$->setMatch(CSSSelector::PseudoClass);
1359 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4)); 1381 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
1360 parser->tokenToLowerCase($2); 1382 parser->tokenToLowerCase($2);
1361 $$->setValue($2); 1383 $$->setValue($2);
1362 CSSSelector::PseudoType type = $$->pseudoType(); 1384 CSSSelector::PseudoType type = $$->pseudoType();
1363 if (type != CSSSelector::PseudoAny) 1385 if (type != CSSSelector::PseudoAny)
1364 YYERROR; 1386 YYERROR;
1365 } 1387 }
1366 | ':' ANYFUNCTION selector_recovery closing_parenthesis { 1388 | ':' ANYFUNCTION selector_recovery closing_parenthesis {
1367 YYERROR; 1389 YYERROR;
1368 } 1390 }
1369 // used by :nth-*(ax+b) 1391 // used by :nth-*(ax+b)
1370 | ':' FUNCTION maybe_space NTH maybe_space closing_parenthesis { 1392 | ':' FUNCTION maybe_space NTH maybe_space closing_parenthesis {
1393 if (!$6)
1394 YYERROR;
1371 $$ = parser->createFloatingSelector(); 1395 $$ = parser->createFloatingSelector();
1372 $$->setMatch(CSSSelector::PseudoClass); 1396 $$->setMatch(CSSSelector::PseudoClass);
1373 $$->setArgument($4); 1397 $$->setArgument($4);
1374 $$->setValue($2); 1398 $$->setValue($2);
1375 CSSSelector::PseudoType type = $$->pseudoType(); 1399 CSSSelector::PseudoType type = $$->pseudoType();
1376 if (type == CSSSelector::PseudoUnknown) 1400 if (type == CSSSelector::PseudoUnknown)
1377 YYERROR; 1401 YYERROR;
1378 } 1402 }
1379 // used by :nth-* 1403 // used by :nth-*
1380 | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space closing_ parenthesis { 1404 | ':' FUNCTION maybe_space maybe_unary_operator INTEGER maybe_space closing_ parenthesis {
1405 if (!$7)
1406 YYERROR;
1381 $$ = parser->createFloatingSelector(); 1407 $$ = parser->createFloatingSelector();
1382 $$->setMatch(CSSSelector::PseudoClass); 1408 $$->setMatch(CSSSelector::PseudoClass);
1383 $$->setArgument(AtomicString::number($4 * $5)); 1409 $$->setArgument(AtomicString::number($4 * $5));
1384 $$->setValue($2); 1410 $$->setValue($2);
1385 CSSSelector::PseudoType type = $$->pseudoType(); 1411 CSSSelector::PseudoType type = $$->pseudoType();
1386 if (type == CSSSelector::PseudoUnknown) 1412 if (type == CSSSelector::PseudoUnknown)
1387 YYERROR; 1413 YYERROR;
1388 } 1414 }
1389 // used by :nth-*(odd/even) and :lang 1415 // used by :nth-*(odd/even) and :lang
1390 | ':' FUNCTION maybe_space IDENT maybe_space closing_parenthesis { 1416 | ':' FUNCTION maybe_space IDENT maybe_space closing_parenthesis {
1417 if (!$6)
1418 YYERROR;
1391 $$ = parser->createFloatingSelector(); 1419 $$ = parser->createFloatingSelector();
1392 $$->setMatch(CSSSelector::PseudoClass); 1420 $$->setMatch(CSSSelector::PseudoClass);
1393 $$->setArgument($4); 1421 $$->setArgument($4);
1394 parser->tokenToLowerCase($2); 1422 parser->tokenToLowerCase($2);
1395 $$->setValue($2); 1423 $$->setValue($2);
1396 CSSSelector::PseudoType type = $$->pseudoType(); 1424 CSSSelector::PseudoType type = $$->pseudoType();
1397 if (type == CSSSelector::PseudoUnknown) 1425 if (type == CSSSelector::PseudoUnknown)
1398 YYERROR; 1426 YYERROR;
1399 else if (type == CSSSelector::PseudoNthChild || 1427 else if (type == CSSSelector::PseudoNthChild ||
1400 type == CSSSelector::PseudoNthOfType || 1428 type == CSSSelector::PseudoNthOfType ||
1401 type == CSSSelector::PseudoNthLastChild || 1429 type == CSSSelector::PseudoNthLastChild ||
1402 type == CSSSelector::PseudoNthLastOfType) { 1430 type == CSSSelector::PseudoNthLastOfType) {
1403 if (!isValidNthToken($4)) 1431 if (!isValidNthToken($4))
1404 YYERROR; 1432 YYERROR;
1405 } 1433 }
1406 } 1434 }
1407 | ':' FUNCTION selector_recovery closing_parenthesis { 1435 | ':' FUNCTION selector_recovery closing_parenthesis {
1408 YYERROR; 1436 YYERROR;
1409 } 1437 }
1410 // used by :not 1438 // used by :not
1411 | ':' NOTFUNCTION maybe_space simple_selector maybe_space closing_parenthesi s { 1439 | ':' NOTFUNCTION maybe_space simple_selector maybe_space closing_parenthesi s {
1440 if (!$6)
1441 YYERROR;
1412 if (!$4->isSimple()) 1442 if (!$4->isSimple())
1413 YYERROR; 1443 YYERROR;
1414 else { 1444 else {
1415 $$ = parser->createFloatingSelector(); 1445 $$ = parser->createFloatingSelector();
1416 $$->setMatch(CSSSelector::PseudoClass); 1446 $$->setMatch(CSSSelector::PseudoClass);
1417 1447
1418 Vector<OwnPtr<CSSParserSelector> > selectorVector; 1448 Vector<OwnPtr<CSSParserSelector> > selectorVector;
1419 selectorVector.append(parser->sinkFloatingSelector($4)); 1449 selectorVector.append(parser->sinkFloatingSelector($4));
1420 $$->adoptSelectorVector(selectorVector); 1450 $$->adoptSelectorVector(selectorVector);
1421 1451
1422 parser->tokenToLowerCase($2); 1452 parser->tokenToLowerCase($2);
1423 $$->setValue($2); 1453 $$->setValue($2);
1424 } 1454 }
1425 } 1455 }
1426 | ':' NOTFUNCTION selector_recovery closing_parenthesis { 1456 | ':' NOTFUNCTION selector_recovery closing_parenthesis {
1427 YYERROR; 1457 YYERROR;
1428 } 1458 }
1429 | ':' HOSTFUNCTION maybe_space simple_selector_list maybe_space closing_pare nthesis { 1459 | ':' HOSTFUNCTION maybe_space simple_selector_list maybe_space closing_pare nthesis {
1460 if (!$6)
1461 YYERROR;
1430 $$ = parser->createFloatingSelector(); 1462 $$ = parser->createFloatingSelector();
1431 $$->setMatch(CSSSelector::PseudoClass); 1463 $$->setMatch(CSSSelector::PseudoClass);
1432 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4)); 1464 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
1433 parser->tokenToLowerCase($2); 1465 parser->tokenToLowerCase($2);
1434 $$->setValue($2); 1466 $$->setValue($2);
1435 CSSSelector::PseudoType type = $$->pseudoType(); 1467 CSSSelector::PseudoType type = $$->pseudoType();
1436 if (type != CSSSelector::PseudoHost) 1468 if (type != CSSSelector::PseudoHost)
1437 YYERROR; 1469 YYERROR;
1438 } 1470 }
1439 | ':' HOSTFUNCTION selector_recovery closing_parenthesis { 1471 | ':' HOSTFUNCTION selector_recovery closing_parenthesis {
1440 YYERROR; 1472 YYERROR;
1441 } 1473 }
1442 // used by :host-context() 1474 // used by :host-context()
1443 | ':' HOSTCONTEXTFUNCTION maybe_space simple_selector_list maybe_space closi ng_parenthesis { 1475 | ':' HOSTCONTEXTFUNCTION maybe_space simple_selector_list maybe_space closi ng_parenthesis {
1476 if (!$6)
1477 YYERROR;
1444 $$ = parser->createFloatingSelector(); 1478 $$ = parser->createFloatingSelector();
1445 $$->setMatch(CSSSelector::PseudoClass); 1479 $$->setMatch(CSSSelector::PseudoClass);
1446 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4)); 1480 $$->adoptSelectorVector(*parser->sinkFloatingSelectorVector($4));
1447 parser->tokenToLowerCase($2); 1481 parser->tokenToLowerCase($2);
1448 $$->setValue($2); 1482 $$->setValue($2);
1449 CSSSelector::PseudoType type = $$->pseudoType(); 1483 CSSSelector::PseudoType type = $$->pseudoType();
1450 if (type != CSSSelector::PseudoHostContext) 1484 if (type != CSSSelector::PseudoHostContext)
1451 YYERROR; 1485 YYERROR;
1452 } 1486 }
1453 | ':' HOSTCONTEXTFUNCTION selector_recovery closing_parenthesis { 1487 | ':' HOSTCONTEXTFUNCTION selector_recovery closing_parenthesis {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1821 ; 1855 ;
1822 1856
1823 rule_error_recovery: 1857 rule_error_recovery:
1824 /* empty */ 1858 /* empty */
1825 | rule_error_recovery error 1859 | rule_error_recovery error
1826 | rule_error_recovery invalid_square_brackets_block 1860 | rule_error_recovery invalid_square_brackets_block
1827 | rule_error_recovery invalid_parentheses_block 1861 | rule_error_recovery invalid_parentheses_block
1828 ; 1862 ;
1829 1863
1830 %% 1864 %%
OLDNEW
« no previous file with comments | « LayoutTests/fast/css/parsing-unexpected-eof.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698