Wrong code logic to remove URL from Sitemap

Created on 25 October 2023, 8 months ago

Problem/Motivation

When building the Sitemap for my site, the simple_sitemap_hidden_language_remove_language function enter into the condition :

// Check if the language is hidden.
  if (in_array($lang_code, $excluded_languages) || $lang_code == $default_language) {

The first condition : in_array($lang_code, $excluded_languages) returns FALSE (i've only excluded English language, the current URL have the French language).

The second condition : $lang_code == $default_language returns TRUE because my default language is French and the URL language is French too.

The condition $lang_code == $default_language is just used to enter in the condition and run the code below, but in my case i've no URL exceptions listed :

    // If is hidden language exception and is default lang code return false.
    if ($isUrlexception && $lang_code == $default_language) {
      $result[$url] = FALSE;
      return $result[$url];
    }

Finally the code ends and return TRUE (to remove the URL) by the code below :

    // If isn't a hidden language exception or is default lang code return true.
    $result[$url] = TRUE;
    return $result[$url];

It's an regression because it miss to check if the URL langcode is not listed as hidden languages.

Proposed resolution

After checking if ther are URL exceptions, check if the URL language is configured as excluded languages :

    // The URL lang code is not configured as excluded languages, so return 
    // FALSE.
    if (!in_array($lang_code, $excluded_languages)) {
      $result[$url] = FALSE;
      return $result[$url];
    }

otherwise it continue to the existing code :


    // If isn't a hidden language exception or is default lang code return true.
    $result[$url] = TRUE;
    return $result[$url];
πŸ› Bug report
Status

Needs review

Version

2.0

Component

Code

Created by

πŸ‡«πŸ‡·France xavier.masson Haute-Normandie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024