mirror of
https://github.com/servo/servo.git
synced 2025-09-23 05:10:09 +01:00
script: Don't try to evaluate xpath variable references (#39395)
Variables in xpath via the javascript bindings are a bit mysterious, as there is no way that a variable can be specified. We currently panic when encountering a variable, which is not good. Instead we now throw an error. We keep parsing the variables because the code is already there and it seems realistic that their behaviour will be specified in the future. I'm fine with removing them too if that is preferred. Testing: This behaviour is unspecified and different browser produce different results. There is no "correct" way to do this, but we should not crash Part of: https://github.com/servo/servo/issues/34527 --------- Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
e2241a93fe
commit
bdf630563c
3 changed files with 27 additions and 5 deletions
|
@ -33,9 +33,12 @@ pub(crate) enum Error {
|
|||
UnknownFunction {
|
||||
name: QualName,
|
||||
},
|
||||
UnknownVariable {
|
||||
name: QualName,
|
||||
},
|
||||
/// It is not clear where variables used in XPath expression should come from.
|
||||
/// Firefox throws "NS_ERROR_ILLEGAL_VALUE" when using them, chrome seems to return
|
||||
/// an empty result. We also error out.
|
||||
///
|
||||
/// See <https://github.com/whatwg/dom/issues/67>
|
||||
CannotUseVariables,
|
||||
UnknownNamespace {
|
||||
prefix: String,
|
||||
},
|
||||
|
@ -58,7 +61,7 @@ impl std::fmt::Display for Error {
|
|||
Error::NotANodeset => write!(f, "expression did not evaluate to a nodeset"),
|
||||
Error::InvalidPath => write!(f, "invalid path expression"),
|
||||
Error::UnknownFunction { name } => write!(f, "unknown function {:?}", name),
|
||||
Error::UnknownVariable { name } => write!(f, "unknown variable {:?}", name),
|
||||
Error::CannotUseVariables => write!(f, "cannot use variables"),
|
||||
Error::UnknownNamespace { prefix } => {
|
||||
write!(f, "unknown namespace prefix {:?}", prefix)
|
||||
},
|
||||
|
@ -745,7 +748,7 @@ impl Evaluatable for PrimaryExpr {
|
|||
fn evaluate(&self, context: &EvaluationCtx) -> Result<Value, Error> {
|
||||
match self {
|
||||
PrimaryExpr::Literal(literal) => literal.evaluate(context),
|
||||
PrimaryExpr::Variable(_qname) => todo!(),
|
||||
PrimaryExpr::Variable(_qname) => Err(Error::CannotUseVariables),
|
||||
PrimaryExpr::Parenthesized(expr) => expr.evaluate(context),
|
||||
PrimaryExpr::ContextItem => Ok(Value::Nodeset(vec![context.context_node.clone()])),
|
||||
PrimaryExpr::Function(core_function) => core_function.evaluate(context),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue