static inline void cleanPath(Vector<UChar, 512>& path) { // FIXME: Should not do this in the query or anchor part. size_t pos; while ((pos = findSlashDotDotSlash(path.data(), path.size())) != notFound) { size_t prev = reverseFind(path.data(), path.size(), '/', pos - 1); // don't remove the host, i.e. http://foo.org/../foo.html if (prev == notFound || (prev > 3 && path[prev - 2] == ':' && path[prev - 1] == '/')) path.remove(pos, 3); else path.remove(prev, pos - prev + 3); } // FIXME: Should not do this in the query part. pos = 0; if ((pos = findSlashSlash(path.data(), path.size(), pos)) != notFound) { size_t refPos = find(path.data(), path.size(), '#'); while (refPos == 0 || refPos == notFound || pos < refPos) { if (pos == 0 || path[pos - 1] != ':') path.remove(pos); else pos += 2; if ((pos = findSlashSlash(path.data(), path.size(), pos)) == notFound) break; } } // FIXME: Should not do this in the query or anchor part. while ((pos = findSlashDotSlash(path.data(), path.size())) != notFound) path.remove(pos, 2); }
static inline void cleanPath(Vector<UChar, 512>& path) { // FIXME: Should not do this in the query or anchor part. int pos; while ((pos = findSlashDotDotSlash(path.data(), path.size())) != -1) { int prev = reverseFind(path.data(), path.size(), '/', pos - 1); // don't remove the host, i.e. http://foo.org/../foo.html if (prev < 0 || (prev > 3 && path[prev - 2] == ':' && path[prev - 1] == '/')) path.remove(pos, 3); else path.remove(prev, pos - prev + 3); } // FIXME: Should not do this in the query part. // Set refPos to -2 to mean "I haven't looked for the anchor yet". // We don't want to waste a function call on the search for the the anchor // in the vast majority of cases where there is no "//" in the path. pos = 0; int refPos = -2; while ((pos = findSlashSlash(path.data(), path.size(), pos)) != -1) { if (refPos == -2) refPos = find(path.data(), path.size(), '#'); if (refPos > 0 && pos >= refPos) break; if (pos == 0 || path[pos - 1] != ':') path.remove(pos); else pos += 2; } // FIXME: Should not do this in the query or anchor part. while ((pos = findSlashDotSlash(path.data(), path.size())) != -1) path.remove(pos, 2); }
static inline void cleanPath(Vector<UChar, 512>& path) { // FIXME: Should not do this in the query or anchor part of the URL. size_t firstSlash = findSlashDotDotSlash(path.data(), path.size(), 0); if (firstSlash != notFound) cleanSlashDotDotSlashes(path, firstSlash); // FIXME: Should not do this in the query part. firstSlash = findSlashSlash(path.data(), path.size(), 0); if (firstSlash != notFound) mergeDoubleSlashes(path, firstSlash); // FIXME: Should not do this in the query or anchor part. firstSlash = findSlashDotSlash(path.data(), path.size(), 0); if (firstSlash != notFound) cleanSlashDotSlashes(path, firstSlash); }
static void mergeDoubleSlashes(Vector<UChar, 512>& path, size_t firstSlash) { size_t refPos = find(path.data(), path.size(), '#'); if (!refPos || refPos == notFound) refPos = path.size(); size_t slash = firstSlash; while (slash < refPos) { if (!slash || path[slash - 1] != ':') path[slash++] = 0; else slash += 2; if ((slash = findSlashSlash(path.data(), path.size(), slash)) == notFound) break; } squeezeOutNullCharacters(path); }