Commit 7881c7bf authored by Alice Wyan's avatar Alice Wyan

Reject annotation anchoring when no quote selector found

parent 1017c930
...@@ -50,6 +50,11 @@ exports.anchor = (root, selectors, options = {}) -> ...@@ -50,6 +50,11 @@ exports.anchor = (root, selectors, options = {}) ->
when 'RangeSelector' when 'RangeSelector'
range = selector range = selector
# Assert that there is a quote selector, since otherwise we cannot validate
# the rest of the annotation's selectors.
if not quote?
return Promise.reject(new Error('quote selector not found'))
# Assert the quote matches the stored quote, if applicable # Assert the quote matches the stored quote, if applicable
maybeAssertQuote = (range) -> maybeAssertQuote = (range) ->
if quote?.exact? and range.toString() != quote.exact if quote?.exact? and range.toString() != quote.exact
......
...@@ -99,4 +99,22 @@ describe('anchoring', function () { ...@@ -99,4 +99,22 @@ describe('anchoring', function () {
], ],
expectFail: true, expectFail: true,
}]); }]);
unroll('should silently fail when an annotation does not have a quote selector', function (testCase) {
var annotation = testCase.annotation;
var anchored = guest.anchor(annotation);
return anchored.then(function (result) {
assert.deepEqual(result, []);
});
}, [{
annotation: [{
target: [{
selector: [{
type: 'FragmentSelector',
value: 't=30,60'
}]
}]
}],
}]);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment