Skip to content

Commit

Permalink
prevent crash if sentence is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsumoto-ren committed Mar 23, 2021
1 parent f50882c commit 7c9de23
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions subs2srs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,12 @@ local function update_sentence(new_data, stored_data)
-- adds support for TSCs
-- https://tatsumoto-ren.github.io/blog/discussing-various-card-templates.html#targeted-sentence-cards-or-mpvacious-cards
-- if the target word was marked by yomichan, this function makes sure that the highlighting doesn't get erased.

if is_empty(stored_data[config.sentence_field]) then
-- sentence field is empty. can't continue.
return new_data
end

local _, opentag, target, closetag, _ = stored_data[config.sentence_field]:match('^(.-)(<[^>]+>)(.-)(</[^>]+>)(.-)$')
if target then
local prefix, _, suffix = new_data[config.sentence_field]:match(table.concat { '^(.-)(', target, ')(.-)$' })
Expand Down

0 comments on commit 7c9de23

Please sign in to comment.