Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Quote bugfix #47

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/queryselector/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl<'a> Parser<'a> {
}
Some(b'=') => {
self.stream.advance();
self.stream.expect_and_skip(b'"')?;
let value = self.read_identifier();
self.stream.expect_and_skip(b'"')?;
mehmetcansahin marked this conversation as resolved.
Show resolved Hide resolved
self.stream.expect_and_skip(b']')?;
Selector::AttributeValue(attribute, value)
}
Expand Down
29 changes: 29 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,35 @@ mod query_selector {
"PASS"
);
}

#[test]
fn query_selector_with_quote() {
let input = r#"<div><meta property="og:title" content="hello" /></div>"#;
let dom = parse(input, ParserOptions::default()).unwrap();
let parser = dom.parser();
let node_option = dom
.query_selector(r#"meta[property="og:title"]"#)
.and_then(|mut iter| iter.next());
let value = if let Some(node) = node_option {
Some(
node.get(parser)
.unwrap()
.as_tag()
.unwrap()
.attributes()
.get("content")
.flatten()
.unwrap()
.try_as_utf8_str()
.unwrap()
.to_string(),
)
} else {
None
};

assert_eq!(value, Some("hello".to_string()));
}
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub fn is_ident(c: u8) -> bool {
|| (b'a'..=b'z').contains(&c)
|| c == b'-'
|| c == b'_'
|| c == b':'
}

#[inline(always)]
Expand Down