From 2a313c07eee1864e757d0864d4fe8a430745fd72 Mon Sep 17 00:00:00 2001 From: Cameron Purdy <699204+cpurdy@users.noreply.github.com> Date: Sat, 11 Jan 2025 16:42:10 -0500 Subject: [PATCH] Patch for URI --- lib_net/src/main/x/net/Uri.x | 11 +++++---- lib_net/src/main/x/net/UriTemplate.x | 35 +++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lib_net/src/main/x/net/Uri.x b/lib_net/src/main/x/net/Uri.x index c082c7032..640e4ef32 100644 --- a/lib_net/src/main/x/net/Uri.x +++ b/lib_net/src/main/x/net/Uri.x @@ -832,6 +832,9 @@ const Uri Int endOffset = totalLength; if (isLast && end.offset < endOffset) { endOffset = end.offset; + if (offset == endOffset) { + return True; + } } if (String prefix ?= section.prefix) { Int partLen = prefix.size; @@ -839,17 +842,17 @@ const Uri prefix[offset.. expand(Appender buf, Lookup values) { for (Variable var : vars) { @@ -482,24 +489,34 @@ const UriTemplate { @Override conditional (Position after, Map bindings) matches(Uri uri, Position from, Position? to, Char? nextPrefix, Map bindings) { + // we can only match if we are inside the correct section + if (!(from := uri.positionAt(from, onlyWithin))) { + return False; + } + String sectionText = uri.sectionText(onlyWithin); Int sectionLength = sectionText.size; if (sectionLength == 0) { + if (prefix == nextPrefix) { + // this is a conservative decision, but will not always be correct; the + // assumption here is that a multi-part section can't have multiple parts + // if it doesn't have any parts; it may need to be re-worked if a use case + // arises where multiple empty parts are desired + return False; + } for (Variable var : vars) { if (var.require) { // no text, no match (because even the prefix is absent) return False; + } else { + bindings = mutate(bindings).put(var.name, var.explode ? defaultExplodedValue : defaultValue); } } + return True, from, bindings; } - // we can only match if we are inside the correct section - if (!(from := uri.positionAt(from, onlyWithin))) { - return False; - } Int fromOffset = from.offset; - - Int toOffset = sectionLength; + Int toOffset = sectionLength; to := uri.positionAt(to?, onlyWithin); switch (to?.section <=> onlyWithin) { case Lesser: @@ -613,6 +630,12 @@ const UriTemplate { return '?'; } + @Override + Value defaultExplodedValue.get() { + static Map EmptyMap = []; + return EmptyMap; + } + @Override conditional (Position after, Map bindings) matches(Uri uri, Position from, Position? to, Char? nextPrefix, Map bindings) {