Repository: xbmc/xbmc
File: xbmc/video/VideoInfoScanner.cpp (C++)

Code before:
        int currentEpisode{episode.iEpisode};

        // we want "long circuit" OR below so that both offsets are evaluated
        while (static_cast<int>((regexp2pos = reg2.RegFind(remainder.c_str() + offset)) > -1) |
               static_cast<int>((regexppos = reg.RegFind(remainder.c_str() + offset)) > -1))
        {
          if ((regexppos <= regexp2pos && regexppos != -1) || // season (or 'ep') match
              (regexppos >= 0 && regexp2pos == -1))
          {
            GetEpisodeAndSeasonFromRegExp(reg, episode, defaultSeason);
            if (currentSeason == episode.iSeason)
            {
              // Already added SxxEyy now loop (if needed) to SxxEzz
              const int last{episode.iEpisode};
              const int next{disableEpisodeRanges ? last : currentEpisode + 1};

              ProcessEpisodeRange(next, last, episode, episodeList,
                                  m_advancedSettings->m_tvshowMultiPartEnumRegExp);

              currentEpisode = episode.iEpisode;
              remainder = reg.GetMatch(3);
            }
            else
            {
              // Two possible scenarios here:
              if (!remainder.starts_with("-"))
              {
                // (Sxx)Eyy has already been added and we now in a new range (eg. S00E01S01E01....)
                // Add first episode here
                currentSeason = episode.iSeason;
                currentEpisode = episode.iEpisode;
                episodeList.push_back(episode);
                remainder = reg.GetMatch(3);
              }
              else
              {
                // (Sxx)Eyy has already been added as start of range and we now have SaaEbb (eg. S01E01-S02E05)
                //   this is not allowed as scanner cannot determine how many episodes in a season
                if (offset == 0)
                {
                  // Already added first episode of invalid range so remove it
                  episodeList.pop_back();
                  remainder = reg.GetMatch(3);
                  CLog::LogF(
                      LOGDEBUG,
                      "VideoInfoScanner: Removing season {}, episode {} as part of invalid range",
                      episode.iSeason, episode.iEpisode);
                }
                else
                  remainder = remainder.substr(offset);
              }

Review comment (bug):
Needs to take the offset into account I think.
try the case
{"foo S00E01E03-S01E01.mkv", {{0, 1}, {0, 3}}, {{0, 1}, {0, 3}, {1, 1}}},
with current error handling, is supposed to fail the second season the same way it does for foo.S01E01-S02E03.mkv

Code after:
        int currentSeason{episode.iSeason};
        int currentEpisode{episode.iEpisode};

        // we want "long circuit" OR below so that both offsets are evaluated
        while (static_cast<int>((regexp2pos = reg2.RegFind(remainder.c_str() + offset)) > -1) |
               static_cast<int>((regexppos = reg.RegFind(remainder.c_str() + offset)) > -1))
        {
          if ((regexppos <= regexp2pos && regexppos != -1) || // season (or 'ep') match
              (regexppos >= 0 && regexp2pos == -1))
          {
            GetEpisodeAndSeasonFromRegExp(reg, episode, defaultSeason);
            if (currentSeason == episode.iSeason)
            {
              // Already added SxxEyy now loop (if needed) to SxxEzz
              const int last{episode.iEpisode};
              const int next{
                  disableEpisodeRanges || !remainder.starts_with("-") ? last : currentEpisode + 1};

              ProcessEpisodeRange(next, last, episode, episodeList,
                                  m_advancedSettings->m_tvshowMultiPartEnumRegExp);

              currentEpisode = episode.iEpisode;
              remainder = reg.GetMatch(3);
            }
            else
            {
              // Two possible scenarios here:
              if (remainder.substr(offset, 1) != "-" || disableEpisodeRanges)
              {
                // (Sxx)Eyy has already been added and we now in a new range (eg. S00E01S01E01....)
                // Add first episode here
                currentSeason = episode.iSeason;
                currentEpisode = episode.iEpisode;
                episodeList.push_back(episode);
                remainder = reg.GetMatch(3);
              }
              else
              {
                // (Sxx)Eyy has already been added as start of range and we now have SaaEbb (eg. S01E01-S02E05)
                //   this is not allowed as scanner cannot determine how many episodes in a season
                if (offset == 0)
                {
                  // Already added first episode of invalid range so remove it
                  episodeList.pop_back();
                  remainder = reg.GetMatch(3);
                  CLog::LogF(
                      LOGDEBUG,
                      "VideoInfoScanner: Removing season {}, episode {} as part of invalid range",
                      episode.iSeason, episode.iEpisode);
                }
                else