Replace \ by / to make libxml2 happy on Windows and replace "a/b/../c" pattern by "a/c".
| 74 | // Replace \ by / to make libxml2 happy on Windows and |
| 75 | // replace "a/b/../c" pattern by "a/c". |
| 76 | static void CPLFixPath(char *pszPath) |
| 77 | { |
| 78 | for (int i = 0; pszPath[i] != '\0'; ++i) |
| 79 | { |
| 80 | if (pszPath[i] == '\\') |
| 81 | pszPath[i] = '/'; |
| 82 | } |
| 83 | |
| 84 | std::string osRet(pszPath); |
| 85 | while (true) |
| 86 | { |
| 87 | size_t nSlashDotDot = osRet.find("/../"); |
| 88 | if (nSlashDotDot == std::string::npos || nSlashDotDot == 0) |
| 89 | break; |
| 90 | size_t nPos = nSlashDotDot - 1; |
| 91 | while (nPos > 0 && osRet[nPos] != '/') |
| 92 | --nPos; |
| 93 | if (nPos == 0) |
| 94 | break; |
| 95 | osRet = osRet.substr(0, nPos + 1) + |
| 96 | osRet.substr(nSlashDotDot + strlen("/../")); |
| 97 | } |
| 98 | memcpy(pszPath, osRet.data(), osRet.size() + 1); |
| 99 | } |
| 100 | |
| 101 | #ifdef HAS_VALIDATION_BUG |
| 102 |
no test coverage detected