Repository: xbmc/xbmc
File: xbmc/utils/URIUtils.cpp (C++)

Code before:

  url.SetFileName(strFile);
  strParent = url.Get();
  return true;
}

std::string URIUtils::GetBasePath(const std::string& strPath)
{
  std::string strCheck{strPath};
  if (IsStack(strPath))
    strCheck = CStackDirectory::GetFirstStackedFile(strPath);

  std::string strDirectory = GetDirectory(strCheck);

  if (IsInRAR(strCheck))
  {
    std::string path{strDirectory};
    GetParentPath(path, strDirectory);
  }

  if (IsBDFile(strCheck))
    strDirectory = GetDiscBasePath(strCheck);

  if (IsBlurayPath(strCheck))
    strDirectory = CBlurayDirectory::GetBasePath(CURL(strCheck));

  if (IsStack(strPath))
  {
    strCheck = strDirectory;
    RemoveSlashAtEnd(strCheck);
    if (GetFileName(strCheck).size() == 3 && StringUtils::StartsWithNoCase(GetFileName(strCheck), "cd"))
      strDirectory = GetDirectory(strCheck);
  }

  return strDirectory;
}

std::string URIUtils::GetDiscBase(const std::string& file)
{
  std::string discFile;
  if (IsBlurayPath(file))
    discFile = GetBlurayFile(file);
  else
    discFile = file;

  std::string parent{GetParentPath(discFile)};
  std::string parentFolder{parent};
  RemoveSlashAtEnd(parentFolder);
  parentFolder = GetFileName(parentFolder);
  if (StringUtils::EqualsNoCase(parentFolder, "VIDEO_TS") ||
      StringUtils::EqualsNoCase(parentFolder, "BDMV"))

Review comment (security):
did this pass ci? i'm getting a linker error when building on Debian 12
```
[100%] Linking CXX executable kodi-x11
build/utils/utils.a(URIUtils.cpp.o):URIUtils.cpp:function URIUtils::GetBasePath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&):

error: undefined reference to 'XFILE::CBlurayDirectory::GetBasePath[abi:cxx11](CURL const&)'
collect2: error: ld returned 1 exit status

gmake[2]: *** [CMakeFiles/kodi.dir/build.make:540: kodi-x11] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:5625: CMakeFiles/kodi.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

6451b7937d811203597f902add034710a74958ab is the first bad commit
commit 6451b7937d811203597f902add034710a74958ab
Author: 78andyp <99039295+78andyp@users.noreply.github.com>
Date:   Mon May 26 22:14:11 2025 +0100

    Fix retrieval of basepath.
    
    Looking at the existing code basepath is different to the actual path of the media file, it is where the actual physical file resides (eg. for an archive:// path the basepath is the path in which the archive file itself resides not the media contained therein which the archive:// path+file points to, and for BD file structure its the movie directory not the BDMV directory with index.BDMV).

 xbmc/filesystem/BlurayDirectory.cpp |  2 +-
 xbmc/utils/URIUtils.cpp             | 16 +++++++++++++---
 xbmc/video/VideoDatabase.cpp        |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)
```

Code after:
  AddSlashAtEnd(strFile);

  url.SetFileName(strFile);
  strParent = url.Get();
  return true;
}

std::string URIUtils::GetBasePath(const std::string& strPath)
{
  std::string strCheck{strPath};
  if (IsStack(strPath))
    strCheck = CStackDirectory::GetFirstStackedFile(strPath);

  std::string strDirectory = GetDirectory(strCheck);

  if (IsInRAR(strCheck))
  {
    std::string path{strDirectory};
    GetParentPath(path, strDirectory);
  }

  if (IsBDFile(strCheck))
    strDirectory = GetDiscBasePath(strCheck);

  if (IsBlurayPath(strCheck))
    strDirectory = CBlurayDirectory::GetBasePath(CURL(strCheck));

  if (IsStack(strPath))
  {
    strCheck = strDirectory;
    RemoveSlashAtEnd(strCheck);
    if (GetFileName(strCheck).size() == 3 && StringUtils::StartsWithNoCase(GetFileName(strCheck), "cd"))
      strDirectory = GetDirectory(strCheck);
  }

  return strDirectory;
}

bool URIUtils::IsDiscPath(const std::string& path)
{
  std::string folder{path};
  RemoveSlashAtEnd(folder);
  folder = GetFileName(folder);
  return StringUtils::EqualsNoCase(folder, "VIDEO_TS") || StringUtils::EqualsNoCase(folder, "BDMV");
}

std::string URIUtils::GetDiscBase(const std::string& file)
{
  std::string discFile;
  if (IsBlurayPath(file))
    discFile = GetBlurayFile(file);