This is an automated email from the ASF dual-hosted git repository.

cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit b4a30c9839a8e032bf22f89bd40acf69037fd75f
Author: Leif Hedstrom <[email protected]>
AuthorDate: Fri Aug 22 11:37:34 2025 -0600

    Cripts: Fix standalone query and path URI components (#12462)
    
    This fixes a regression introduced with the Convenience APIs,
    and is a rare edge cases where URI components can be created
    outside of an owning URL.
    
    (cherry picked from commit a0c0ee642e55f55eecd8446ed82fcebfd8fb6385)
---
 include/cripts/Urls.hpp | 10 ++++++----
 src/cripts/Urls.cc      | 12 +++++++++---
 2 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/include/cripts/Urls.hpp b/include/cripts/Urls.hpp
index 47c8c5069e..eba50c64f0 100644
--- a/include/cripts/Urls.hpp
+++ b/include/cripts/Urls.hpp
@@ -461,9 +461,10 @@ public:
 
     Query(cripts::string_view load)
     {
-      _data   = load;
-      _size   = load.size();
-      _loaded = true;
+      _data       = load;
+      _size       = load.size();
+      _loaded     = true;
+      _standalone = true;
     }
 
     void Reset() override;
@@ -515,7 +516,8 @@ public:
   private:
     void _parser();
 
-    bool           _modified = false;
+    bool           _modified   = false;
+    bool           _standalone = false;  // This component is used outside of 
a URL owner, not common
     OrderedParams  _ordered;             // Ordered vector of all parameters, 
can be sorted etc.
     HashParams     _hashed;              // Unordered map to go from "name" to 
the query parameter
     cripts::string _storage;             // Used when recombining the query 
params into a
diff --git a/src/cripts/Urls.cc b/src/cripts/Urls.cc
index 749b802602..94822baf62 100644
--- a/src/cripts/Urls.cc
+++ b/src/cripts/Urls.cc
@@ -228,6 +228,7 @@ Url::Path::_parser()
 Url::Query::Parameter &
 Url::Query::Parameter::operator=(const cripts::string_view str)
 {
+  CAssert(!_owner->_standalone);
   _ensure_initialized(_owner->_owner);
   CAssert(!_owner->_owner->ReadOnly()); // This can not be a read-only URL
   auto iter = _owner->_hashed.find(_name);
@@ -246,7 +247,9 @@ Url::Query::Parameter::operator=(const cripts::string_view 
str)
 cripts::string_view
 Url::Query::GetSV()
 {
-  _ensure_initialized(_owner);
+  if (!_standalone) {
+    _ensure_initialized(_owner);
+  }
   if (_ordered.size() > 0) {
     _storage.clear();
     _storage.reserve(_size);
@@ -290,6 +293,7 @@ Url::Query::GetSV()
 Url::Query
 Url::Query::operator=(cripts::string_view query)
 {
+  CAssert(!_standalone);
   _ensure_initialized(_owner);
   CAssert(!_owner->ReadOnly()); // This can not be a read-only URL
   TSUrlHttpQuerySet(_owner->_bufp, _owner->_urlp, query.data(), query.size());
@@ -317,8 +321,10 @@ Url::Query::operator+=(cripts::string_view add)
 Url::Query::Parameter
 Url::Query::operator[](cripts::string_view param)
 {
-  // Make sure the hash and vector are populated
-  _ensure_initialized(_owner);
+  // Make sure the hash and vector are populated, but only if we have an owner
+  if (!_standalone) {
+    _ensure_initialized(_owner);
+  }
   _parser();
 
   Parameter ret;

Reply via email to