Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 34 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ assert_cmd = "2.2"
clap = "4.6"
criterion = { version = "0.8", default-features = false }
csv = "1.4"
cssparser = "0.37"
cssparser = "0.38"
encoding_rs = "0.8"
html5ever = "0.40"
is-terminal = "0.4"
Expand All @@ -39,7 +39,7 @@ scrape-cli = { path = "crates/scrape-cli", version = "0.2.13" }
scrape-core = { path = "crates/scrape-core", default-features = false, version = "0.2.13" }
scraper = "0.27"
select = "0.6"
selectors = "0.40"
selectors = "0.41"
serde = "1.0"
serde_json = "1.0"
tempfile = "3.27"
Expand Down
28 changes: 10 additions & 18 deletions crates/scrape-core/src/query/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ pub enum NonTSPseudoClass {
}

impl selectors::parser::NonTSPseudoClass for NonTSPseudoClass {
type Impl = ScrapeSelector;

fn is_active_or_hover(&self) -> bool {
false
}
Expand All @@ -181,9 +179,7 @@ impl ToCss for NonTSPseudoClass {
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PseudoElement {}

impl selectors::parser::PseudoElement for PseudoElement {
type Impl = ScrapeSelector;
}
impl selectors::parser::PseudoElement for PseudoElement {}

impl ToCss for PseudoElement {
fn to_css<W>(&self, _dest: &mut W) -> fmt::Result
Expand Down Expand Up @@ -213,22 +209,18 @@ struct SelectorParser;

impl<'i> Parser<'i> for SelectorParser {
type Impl = ScrapeSelector;
type Error = SelectorParseErrorKind<'i>;
type Error = SelectorParseErrorKind;

fn parse_non_ts_pseudo_class(
&self,
location: cssparser::SourceLocation,
name: cssparser::CowRcStr<'i>,
) -> Result<NonTSPseudoClass, cssparser::ParseError<'i, Self::Error>> {
) -> Result<NonTSPseudoClass, cssparser::ParseError<Self::Error>> {
match name.as_ref() {
"link" => Ok(NonTSPseudoClass::Link),
"any-link" => Ok(NonTSPseudoClass::AnyLink),
_ => Err(cssparser::ParseError {
kind: cssparser::ParseErrorKind::Custom(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name),
),
location,
}),
_ => Err(cssparser::ParseError::custom(
SelectorParseErrorKind::UnsupportedPseudoClassOrElement,
)),
}
}
}
Expand All @@ -247,15 +239,15 @@ impl<'i> Parser<'i> for SelectorParser {
/// let selectors = parse_selector("div.container > span").unwrap();
/// ```
pub fn parse_selector(selector: &str) -> QueryResult<SelectorList<ScrapeSelector>> {
let mut parser_input = cssparser::ParserInput::new(selector);
let mut parser = cssparser::Parser::new(&mut parser_input);
let mut parser = cssparser::Parser::new(selector);

SelectorList::parse(&SelectorParser, &mut parser, ParseRelative::No).map_err(|e| {
SelectorList::parse(&SelectorParser, &mut parser, ParseRelative::No).map_err(|_| {
// Sanitize error messages to expose only position info, avoiding potential
// information disclosure from internal parser state in public error messages.
let location = parser.current_source_location();
QueryError::invalid_selector(format!(
"invalid selector at line {}, column {}",
e.location.line, e.location.column
location.line, location.column
))
})
}
Expand Down
Loading