Skip to content

Commit

Permalink
Fixed IQ Puzzles statuses resetting on update
Browse files Browse the repository at this point in the history
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 53ba184)
  • Loading branch information
revolter committed Jun 22, 2024
1 parent 53ba184 commit 50c0c15
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/recipes/iq_puzzles/IQPuzzlesRecipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 50c0c15

Please sign in to comment.