Skip to content

Commit 39613cc

Browse files
committed
Don't allow leading bar.
1 parent 1bdebb7 commit 39613cc

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/lib.rs

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -189,35 +189,20 @@ impl<'a, 'b, I: Impl> Parser<'a, 'b, I> {
189189
fn parse(&mut self) -> Result<(), ParseError> {
190190
// 5. Repeatedly consume the next input code point from stream:
191191
loop {
192+
let component = self.parse_component()?;
193+
self.output.push(component);
194+
self.skip_whitespace();
195+
192196
let byte = match self.peek() {
193-
None => {
194-
// EOF: If descriptor's size is greater than zero, return
195-
// descriptor; otherwise, return failure.
196-
if self.output.is_empty() {
197-
return Err(ParseError::UnexpectedEOF);
198-
}
199-
return Ok(());
200-
}
197+
None => return Ok(()),
201198
Some(b) => b,
202199
};
203200

204-
// whitespace: Do nothing.
205-
if is_whitespace(byte) {
206-
self.position += 1;
207-
continue;
208-
}
209-
210-
// Intentional deviation from the spec, see:
211-
// https://github.com/w3c/css-houdini-drafts/issues/893
212-
if !self.output.is_empty() && byte != b'|' {
201+
if byte != b'|' {
213202
return Err(ParseError::ExpectedPipeBetweenComponents);
214203
}
215204

216-
if byte == b'|' {
217-
self.position += 1;
218-
}
219-
let component = self.parse_component()?;
220-
self.output.push(component);
205+
self.position += 1;
221206
}
222207
}
223208

@@ -331,6 +316,11 @@ mod tests {
331316
}
332317
}
333318

319+
#[test]
320+
fn leading_bar() {
321+
assert!(parse_descriptor("|<length>").is_err());
322+
}
323+
334324
#[test]
335325
fn simple_length() {
336326
assert_eq!(parse_descriptor("foo | <length>#"), Ok(Descriptor(Box::new([

0 commit comments

Comments
 (0)