Skip to content

Commit f59985c

Browse files
committed
Merge branch 'master' into overflow
2 parents 6bfbfc1 + 7f862d8 commit f59985c

File tree

9 files changed

+184
-143
lines changed

9 files changed

+184
-143
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ license = "MPL-2.0"
1414

1515
[dev-dependencies]
1616
rustc-serialize = "0.3"
17+
tempdir = "0.3"
1718

1819

1920
[dependencies]

src/color.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use std::ascii::AsciiExt;
66
use std::fmt;
7-
use std::num::Float;
87

98
use text_writer::{self, TextWriter};
109

src/css-parsing-tests/component_value_list.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,23 @@
380380
["unicode-range", 1048576, 2097151], "?"
381381
],
382382

383-
"u+1-2 U+100000-2 U+1000000-2 U+10-200000", [
384-
["unicode-range", 1, 2], " ",
383+
"u+20-3F U+100000-2 U+1000000-2 U+10-200000", [
384+
["unicode-range", 32, 63], " ",
385385
["unicode-range", 1048576, 2], " ",
386386
["unicode-range", 1048576, 1048576], ["number", "0", 0, "integer"],
387387
["number", "-2", -2, "integer"], " ",
388388
["unicode-range", 16, 2097152]
389389
],
390390

391-
"ù+12 Ü+12 u +12 U+ 12 U+12 - 20 U+1?2 U+1?-50", [
391+
"ù+12 Ü+12 u +12 U+ 12 U+12 - 20 U+1?2 U+1?-50 U+1- 2", [
392392
["ident", "ù"], ["number", "+12", 12, "integer"], " ",
393393
["ident", "Ü"], ["number", "+12", 12, "integer"], " ",
394394
["ident", "u"], " ", ["number", "+12", 12, "integer"], " ",
395395
["ident", "U"], "+", " ", ["number", "12", 12, "integer"], " ",
396396
["unicode-range", 18, 18], " ", "-", " ", ["number", "20", 20, "integer"], " ",
397397
["unicode-range", 16, 31], ["number", "2", 2, "integer"], " ",
398-
["unicode-range", 16, 31], ["number", "-50", -50, "integer"]
398+
["unicode-range", 16, 31], ["number", "-50", -50, "integer"], " ",
399+
["unicode-range", 1, 1], "-", " ", ["number", "2", 2, "integer"]
399400
],
400401

401402
"~=|=^=$=*=||<!------> |/**/| ~/**/=", [

src/from_bytes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn decode_stylesheet_bytes(css: &[u8], protocol_encoding_label: Option<&str>
3535
if css.starts_with("@charset \"".as_bytes()) {
3636
// 10 is "@charset \"".len()
3737
// 100 is arbitrary so that no encoding label is more than 100-10 bytes.
38-
match css[10..cmp::min(css.len(), 100)].position_elem(&('"' as u8)) {
38+
match css[10..cmp::min(css.len(), 100)].iter().position(|&b| b == b'"') {
3939
None => (),
4040
Some(label_length)
4141
=> if css[10 + label_length..].starts_with("\";".as_bytes()) {

src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
#![crate_name = "cssparser"]
66
#![crate_type = "rlib"]
77

8-
#![feature(core, collections)]
9-
#![cfg_attr(test, feature(test, old_io, old_path))]
108
#![deny(missing_docs)]
119

1210
/*!
@@ -68,8 +66,8 @@ fn parse_border_spacing(_context: &ParserContext, input: &mut Parser)
6866
extern crate encoding;
6967
extern crate text_writer;
7068
#[macro_use] extern crate matches;
71-
#[cfg(test)] extern crate test;
72-
#[cfg(test)] extern crate "rustc-serialize" as serialize;
69+
#[cfg(test)] extern crate tempdir;
70+
#[cfg(test)] extern crate rustc_serialize;
7371

7472
pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation};
7573
pub use rules_and_declarations::{parse_important};
@@ -99,7 +97,7 @@ match_ignore_ascii_case! { string,
9997
}
10098
```
10199
102-
The macro also calls `.as_slice()` on the value,
100+
The macro also takes a slice of the value,
103101
so that a `String` or `CowString` could be passed directly instead of a `&str`.
104102
105103
Note that because of `macro_rules` ambiguity resolutions quirks,
@@ -111,7 +109,7 @@ macro_rules! match_ignore_ascii_case {
111109
( $value: expr, $( $string: expr => $result: expr ),+ _ => $fallback: expr ) => {
112110
{
113111
use std::ascii::AsciiExt;
114-
match $value.as_slice() {
112+
match &$value[..] {
115113
$(
116114
s if s.eq_ignore_ascii_case($string) => $result,
117115
)+

src/parser.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ impl<'i, 't> Parser<'i, 't> {
290290
}
291291

292292
/// Same as `Parser::next`, but does not skip whitespace or comment tokens.
293+
///
294+
/// **Note**: This should only be used in contexts like a CSS pre-processor
295+
/// where comments are preserved.
296+
/// When parsing higher-level values, per the CSS Syntax specification,
297+
/// comments should always be ignored between tokens.
293298
pub fn next_including_whitespace_and_comments(&mut self) -> Result<Token<'i>, ()> {
294299
if let Some(block_type) = self.at_start_of.take() {
295300
consume_until_end_of_block(block_type, &mut *self.tokenizer);
@@ -373,6 +378,9 @@ impl<'i, 't> Parser<'i, 't> {
373378
stop_before: closing_delimiter,
374379
};
375380
result = nested_parser.parse_entirely(parse);
381+
if let Some(block_type) = nested_parser.at_start_of {
382+
consume_until_end_of_block(block_type, &mut *nested_parser.tokenizer);
383+
}
376384
}
377385
consume_until_end_of_block(block_type, &mut *self.tokenizer);
378386
result
@@ -437,6 +445,15 @@ impl<'i, 't> Parser<'i, 't> {
437445
result
438446
}
439447

448+
/// Parse a <whitespace-token> and return its value.
449+
#[inline]
450+
pub fn expect_whitespace(&mut self) -> Result<&'i str, ()> {
451+
match try!(self.next_including_whitespace()) {
452+
Token::WhiteSpace(value) => Ok(value),
453+
_ => Err(())
454+
}
455+
}
456+
440457
/// Parse a <ident-token> and return the unescaped value.
441458
#[inline]
442459
pub fn expect_ident(&mut self) -> Result<Cow<'i, str>, ()> {
@@ -611,6 +628,27 @@ impl<'i, 't> Parser<'i, 't> {
611628
_ => Err(())
612629
}
613630
}
631+
632+
/// Parse the input until exhaustion and check that it contains no “error” token.
633+
///
634+
/// See `Token::is_parse_error`. This also checks nested blocks and functions recursively.
635+
#[inline]
636+
pub fn expect_no_error_token(&mut self) -> Result<(), ()> {
637+
loop {
638+
match self.next_including_whitespace_and_comments() {
639+
Ok(Token::Function(_)) | Ok(Token::ParenthesisBlock) |
640+
Ok(Token::SquareBracketBlock) | Ok(Token::CurlyBracketBlock) => {
641+
try!(self.parse_nested_block(|input| input.expect_no_error_token()))
642+
}
643+
Ok(token) => {
644+
if token.is_parse_error() {
645+
return Err(())
646+
}
647+
}
648+
Err(()) => return Ok(())
649+
}
650+
}
651+
}
614652
}
615653

616654

src/serializer.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use std::fmt;
66
use std::cmp;
7-
use std::num::{Float, Int};
87

98
use text_writer::{self, TextWriter};
109

@@ -49,11 +48,11 @@ pub trait ToCss {
4948
fn write_numeric<W>(value: NumericValue, dest: &mut W) -> text_writer::Result
5049
where W: TextWriter {
5150
// `value.value >= 0` is true for negative 0.
52-
if value.has_sign && value.value.is_positive() {
51+
if value.has_sign && value.value.is_sign_positive() {
5352
try!(dest.write_str("+"));
5453
}
5554

56-
if value.value == 0.0 && value.value.is_negative() {
55+
if value.value == 0.0 && value.value.is_sign_negative() {
5756
// Negative zero. Work around #20596.
5857
try!(dest.write_str("-0"))
5958
} else {
@@ -120,11 +119,13 @@ impl<'a> ToCss for Token<'a> {
120119
Token::UnicodeRange(start, end) => {
121120
try!(dest.write_str("U+"));
122121
let bits = cmp::min(start.trailing_zeros(), (!end).trailing_zeros());
123-
if bits >= 4 && start >> bits == end >> bits {
124-
let question_marks = bits / 4;
125-
let common = start >> question_marks * 4;
126-
if common != 0 {
127-
try!(write!(dest, "{:X}", common));
122+
let question_marks = bits / 4;
123+
let bits = question_marks * 4;
124+
let truncated_start = start >> bits;
125+
let truncated_end = end >> bits;
126+
if truncated_start == truncated_end {
127+
if truncated_start != 0 {
128+
try!(write!(dest, "{:X}", truncated_start));
128129
}
129130
for _ in (0..question_marks) {
130131
try!(dest.write_str("?"));

0 commit comments

Comments
 (0)