diff options
author | Sebastian Pipping <sebastian@pipping.org> | 2021-02-25 21:56:43 +0100 |
---|---|---|
committer | Sebastian Pipping <sebastian@pipping.org> | 2021-02-26 22:26:51 +0100 |
commit | a5f1d0577f5280922d1d5a6d33083f00999e557c (patch) | |
tree | 534e415dd9fbfb842ab974532aa051f25ff3e67f | |
parent | f0d302d4c4d6868c318a08bca9d39c335147f6f8 (diff) | |
download | uriparser-a5f1d0577f5280922d1d5a6d33083f00999e557c.tar.gz |
UriCommon.c: Fix RemoveDotSegmentsEx for URIs like "http://a/.." (fixes #92)
Expected result: http://a/
Actual result: http://a
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | THANKS | 1 | ||||
-rw-r--r-- | src/UriCommon.c | 29 |
3 files changed, 25 insertions, 9 deletions
@@ -4,6 +4,10 @@ NOTE: uriparser is looking for help with a few things: 20xx-xx-x -- x.x.x + * Fixed: Fix a bug regarding section "5.2.4. Remove Dot Segments" + of RFC 3986 that affected both normalization and reference resolution + with regard to trailing slashes. + Thanks to Dan Pape for the report! * Fixed: MinGW: Fix name of static library (GitHub #90) Thanks to SpaceIm for the patch and Sandro Mani for review! * Fixed: Use correct inline marker "__forceinline" for Intel C++ Compiler @@ -7,6 +7,7 @@ Arkadiusz Miskiewicz Blair Sadewitz Chris Hills Cristian Rodriguez +Dan Pape Daniel Chapiesky Daniel Solano Gómez David Demelier diff --git a/src/UriCommon.c b/src/UriCommon.c index 861bf50..7ba92f2 100644 --- a/src/UriCommon.c +++ b/src/UriCommon.c @@ -328,15 +328,26 @@ UriBool URI_FUNC(RemoveDotSegmentsEx)(URI_TYPE(Uri) * uri, * NEW: head <----------- next */ walker->next->reserved = NULL; } else { - /* First and only segment -> update head - * OLD: head -> walker -> NULL - * NEW: head -----------> NULL */ - uri->pathHead = NULL; - - /* Last segment -> update tail - * OLD: tail -> walker - * NEW: tail -> NULL */ - uri->pathTail = NULL; + if (uri->absolutePath) { + /* First and only segment -> update head + * OLD: head -> walker -> NULL + * NEW: head -----------> NULL */ + uri->pathHead = NULL; + + /* Last segment -> update tail + * OLD: tail -> walker + * NEW: tail -> NULL */ + uri->pathTail = NULL; + } else { + /* Re-use segment for "" path segment to represent trailing slash, + * then update head and tail */ + if (pathOwned && (walker->text.first != walker->text.afterLast)) { + memory->free(memory, (URI_CHAR *)walker->text.first); + } + walker->text.first = URI_FUNC(SafeToPointTo); + walker->text.afterLast = URI_FUNC(SafeToPointTo); + freeWalker = URI_FALSE; + } } if (freeWalker) { |