• Robert Knight's avatar
    Fix range selector anchoring in XHTML documents · 39a806fc
    Robert Knight authored
    In HTML documents that have been served with an XML mime type,
    `document.evaluate` handles element names differently. In HTML documents
    the XPath segments do not require prefixes on element names. In XHTML
    documents however they do. Since the client always generates the same
    un-prefixed XPaths regardless of document type, evaluation always
    failed. There was a fallback path but it was only executed if
    `document.evaluate` threw an error, not if it returned `null` as in this
    case.
    
    This commit resolves the issue by first attempting to evaluate the XPath
    using custom logic that only handles simple XPaths and then using
    `document.evaluate` only for more complex XPaths. The _simple XPath_
    logic behaves the same in HTML and XML documents and ignores namespaces.
    As a result it works with the XPaths that the client generates
    regardless of document type and also regardless of whether the XPath
    references only HTML elements or elements from other namespaces (eg.
    MathML or SVG).
    
    We could change the way that the client generates XPaths in future in
    XML documents or SVG/MathML content within HTML documents, but the
    client would still need to handle `RangeSelector` selectors on existing
    annotations.
    
    For more details, see https://github.com/hypothesis/client/pull/2590#issuecomment-702132563
    
    Fixes #2592
    39a806fc
Name
Last commit
Last update
.github Loading commit data...
bin Loading commit data...
dev-server Loading commit data...
docs Loading commit data...
embedding-examples Loading commit data...
images Loading commit data...
scripts Loading commit data...
src Loading commit data...
.babelrc Loading commit data...
.dockerignore Loading commit data...
.eslintignore Loading commit data...
.eslintrc Loading commit data...
.gitignore Loading commit data...
.npmignore Loading commit data...
.npmrc Loading commit data...
.prettierignore Loading commit data...
.prettierrc Loading commit data...
.python-version Loading commit data...
CODE_OF_CONDUCT Loading commit data...
Dockerfile Loading commit data...
Jenkinsfile Loading commit data...
LICENSE Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
codecov.yml Loading commit data...
gulpfile.js Loading commit data...
package.json Loading commit data...
requirements-dev.in Loading commit data...
tox.ini Loading commit data...
yarn.lock Loading commit data...