Fix empty sentence on some search page URLs (#1919)

This commit is contained in:
toasted-nutbread 2021-08-31 20:45:29 -04:00 committed by GitHub
parent 3e7f3af63c
commit ce1a862df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -216,13 +216,14 @@ class DisplayAnki {
if (typeof url !== 'string') {
url = window.location.href;
}
sentence = this._getValidSentenceData(sentence);
const {query, fullQuery} = this._display;
sentence = this._getValidSentenceData(sentence, query);
return {
url,
sentence,
documentTitle,
query: this._display.query,
fullQuery: this._display.fullQuery
query,
fullQuery
};
}
@ -563,10 +564,14 @@ class DisplayAnki {
return isTerms ? ['term-kanji', 'term-kana'] : ['kanji'];
}
_getValidSentenceData(sentence) {
_getValidSentenceData(sentence, fallback) {
let {text, offset} = (isObject(sentence) ? sentence : {});
if (typeof text !== 'string') { text = ''; }
if (typeof offset !== 'number') { offset = 0; }
if (typeof text !== 'string') {
text = fallback;
offset = 0;
} else {
if (typeof offset !== 'number') { offset = 0; }
}
return {text, offset};
}