From 50c0c151f6c93484fe54b79a42b9a173451ad439 Mon Sep 17 00:00:00 2001 From: Iulian Onofrei <5748627+revolter@users.noreply.github.com> Date: Sat, 22 Jun 2024 15:47:52 +0300 Subject: [PATCH] Fixed IQ Puzzles statuses resetting on update If `match` is called with a global RegExp, capturing groups are not included in the return value: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#return_value. As such: > If you want to obtain capture groups and the global flag is set, you > need to use `RegExp.prototype.exec()` or `String.prototype.matchAll()` > instead. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match#description So, since we need only one image, we can safely use `matchAll`, and then only look at the first element. (introduced by 53ba184f) --- src/recipes/iq_puzzles/IQPuzzlesRecipe.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/recipes/iq_puzzles/IQPuzzlesRecipe.ts b/src/recipes/iq_puzzles/IQPuzzlesRecipe.ts index 8725b33..867642e 100644 --- a/src/recipes/iq_puzzles/IQPuzzlesRecipe.ts +++ b/src/recipes/iq_puzzles/IQPuzzlesRecipe.ts @@ -105,8 +105,9 @@ export class IQPuzzlesRecipe implements Recipe { const name = array[0]; const image = array[1]; - const imageLinkMatch = image.match(imageLinkRegex); - if (imageLinkMatch == null || imageLinkMatch.groups == null) { + const imageLinkMatches = Array.from(image.matchAll(imageLinkRegex)); + const imageLinkMatch = imageLinkMatches[0]; + if (imageLinkMatch == undefined || imageLinkMatch == null || imageLinkMatch.groups == null) { return []; } const imageLink = imageLinkMatch.groups.link;