MINOR: uri_normalizer: Add support for supressing leading `../` for dotdot normalizer
This adds an option to supress `../` at the start of the resulting path.
diff --git a/src/uri_normalizer.c b/src/uri_normalizer.c
index 05e8cd5..53a3321 100644
--- a/src/uri_normalizer.c
+++ b/src/uri_normalizer.c
@@ -15,8 +15,13 @@
#include <haproxy/api.h>
#include <haproxy/uri_normalizer.h>
-/* Merges `/../` with preceding path segments. */
-enum uri_normalizer_err uri_normalizer_path_dotdot(const struct ist path, struct ist *dst)
+/* Merges `/../` with preceding path segments.
+ *
+ * If `full` is set to `0` then `/../` will be printed at the start of the resulting
+ * path if the number of `/../` exceeds the number of other segments. If `full` is
+ * set to `1` these will not be printed.
+ */
+enum uri_normalizer_err uri_normalizer_path_dotdot(const struct ist path, int full, struct ist *dst)
{
enum uri_normalizer_err err;
@@ -79,13 +84,15 @@
/* Prepend a trailing slash. */
*(--head) = '/';
- /* Prepend unconsumed `/..`. */
- do {
- *(--head) = '.';
- *(--head) = '.';
- *(--head) = '/';
- up--;
- } while (up > 0);
+ if (!full) {
+ /* Prepend unconsumed `/..`. */
+ do {
+ *(--head) = '.';
+ *(--head) = '.';
+ *(--head) = '/';
+ up--;
+ } while (up > 0);
+ }
}
*dst = ist2(head, tail - head);