Skip to content

Commit a0c0ee6

Browse files
authored
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.
1 parent 938b491 commit a0c0ee6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

include/cripts/Urls.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ class Url
463463

464464
Query(cripts::string_view load)
465465
{
466-
_data = load;
467-
_size = load.size();
468-
_loaded = true;
466+
_data = load;
467+
_size = load.size();
468+
_loaded = true;
469+
_standalone = true;
469470
}
470471

471472
void Reset() override;
@@ -517,7 +518,8 @@ class Url
517518
private:
518519
void _parser();
519520

520-
bool _modified = false;
521+
bool _modified = false;
522+
bool _standalone = false; // This component is used outside of a URL owner, not common
521523
OrderedParams _ordered; // Ordered vector of all parameters, can be sorted etc.
522524
HashParams _hashed; // Unordered map to go from "name" to the query parameter
523525
cripts::string _storage; // Used when recombining the query params into a

src/cripts/Urls.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ Url::Path::_parser()
229229
Url::Query::Parameter &
230230
Url::Query::Parameter::operator=(const cripts::string_view str)
231231
{
232+
CAssert(!_owner->_standalone);
232233
_ensure_initialized(_owner->_owner);
233234
CAssert(!_owner->_owner->ReadOnly()); // This can not be a read-only URL
234235
auto iter = _owner->_hashed.find(_name);
@@ -247,7 +248,9 @@ Url::Query::Parameter::operator=(const cripts::string_view str)
247248
cripts::string_view
248249
Url::Query::GetSV()
249250
{
250-
_ensure_initialized(_owner);
251+
if (!_standalone) {
252+
_ensure_initialized(_owner);
253+
}
251254
if (_ordered.size() > 0) {
252255
_storage.clear();
253256
_storage.reserve(_size);
@@ -291,6 +294,7 @@ Url::Query::GetSV()
291294
Url::Query
292295
Url::Query::operator=(cripts::string_view query)
293296
{
297+
CAssert(!_standalone);
294298
_ensure_initialized(_owner);
295299
CAssert(!_owner->ReadOnly()); // This can not be a read-only URL
296300
TSUrlHttpQuerySet(_owner->_bufp, _owner->_urlp, query.data(), query.size());
@@ -318,8 +322,10 @@ Url::Query::operator+=(cripts::string_view add)
318322
Url::Query::Parameter
319323
Url::Query::operator[](cripts::string_view param)
320324
{
321-
// Make sure the hash and vector are populated
322-
_ensure_initialized(_owner);
325+
// Make sure the hash and vector are populated, but only if we have an owner
326+
if (!_standalone) {
327+
_ensure_initialized(_owner);
328+
}
323329
_parser();
324330

325331
Parameter ret;

0 commit comments

Comments
 (0)