From 8d0419b6acae7e456960071f0f2f72f97a7f1725 Mon Sep 17 00:00:00 2001 From: GHXX Date: Sun, 11 Aug 2024 06:44:33 +0200 Subject: [PATCH] fix inaccessible nodes behaving incorrectly --- SimpleHttpServer/Types/PathTree.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SimpleHttpServer/Types/PathTree.cs b/SimpleHttpServer/Types/PathTree.cs index 812e5fe..1d90615 100644 --- a/SimpleHttpServer/Types/PathTree.cs +++ b/SimpleHttpServer/Types/PathTree.cs @@ -22,12 +22,12 @@ internal class PathTree where T : class { throw new Exception($"Found illegal catchall-wildcard in path: '{string.Join('/', path)}'"); } - var leafdata = unpackedLeafData[i]; + var leafdata = unpackedLeafData[i] ?? throw new ArgumentNullException("Leafdata must not be null!"); rootNode.AddSuccessor(path, leafdata); } } - internal bool TryGetPath(string reqPath, [MaybeNullWhen(false)] out T? endpoint) { + internal bool TryGetPath(string reqPath, [MaybeNullWhen(false)] out T endpoint) { if (rootNode == null) { endpoint = null; return false; @@ -58,16 +58,16 @@ internal class PathTree where T : class { // return found path endpoint = currNode.leafData; - return true; + return endpoint != null; } private class Node { - public T? leafData = null; + public T? leafData = null; // null means that this is a node without a value (e.g. when it is just part of a path) public Dictionary? next = null; public Node? pathWildcardNext = null; // path wildcard public Node? catchAllNext = null; // trailing-catchall wildcard - public void AddSuccessor(string[] segments, T? newLeafData) { + public void AddSuccessor(string[] segments, T newLeafData) { if (segments.Length == 0) { // actually add the data to this node Assert(leafData == null); leafData = newLeafData;