-
Notifications
You must be signed in to change notification settings - Fork 203
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
Fix exception in textMatchScore() when text
is empty
#3538
Fix exception in textMatchScore() when text
is empty
#3538
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3538 +/- ##
=======================================
Coverage 98.60% 98.60%
=======================================
Files 211 211
Lines 7697 7697
Branches 1750 1750
=======================================
Hits 7590 7590
Misses 107 107
Continue to review full report at Codecov.
|
Hello, Thanks for the PR. Would you mind adding a unit test for |
@robertknight Sure, here's the test run from
|
…mpty This could happen in the real application if text near the end of the document was annotated and an update to the document removes the text between the end of the annotated text and the end of the document. I also added a note about the preconditions for when the `search` function is guaranteed to return at least one match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. I made a couple of additional changes on this branch:
- I revised the description of the prefix test to better describe the condition when
text.slice(...)
was producing an empty output before - I added an additional test case that covers a related issue that could happen when generating a score for the suffix match. The existing changes in
textMatchScore
already fixed the problem.
These changes have been shipped in client version v1.809.0. |
Sounds good, thanks for reviewing my PR 👍 |
I observed an exception thrown from
textMatchScore()
iftext
is empty, becausematches[0].errors
is undefined in this case:client/src/annotator/anchoring/match-quote.js
Line 63 in da3a346
An empty
text
occurs when the length of thecontext.prefix
is larger than the prefix of the first match in the page. It gives a negative first parameter for thisslice()
:client/src/annotator/anchoring/match-quote.js
Line 119 in da3a346