Skip to content

Commit 4c4ca98

Browse files
committed
Fixed issue where nullptr was not returned when URL parsing failed
1 parent d361740 commit 4c4ca98

File tree

3 files changed

+65
-52
lines changed

3 files changed

+65
-52
lines changed

src/projects/base/ovlibrary/type.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ namespace ov
2222
using UnderylingType = std::underlying_type_t<T>;
2323
} // namespace ov
2424

25-
#define OV_DEFINE_SETTER(type, setter, member, extra_qualifier, pre_process, post_process) \
26-
void setter(const type &value) extra_qualifier \
27-
{ \
28-
pre_process; \
29-
member = value; \
30-
post_process; \
25+
#define OV_DEFINE_SETTER(value_type, setter_return, setter, member, extra_qualifier, pre_process, post_process) \
26+
setter_return setter(const value_type &value) extra_qualifier \
27+
{ \
28+
pre_process; \
29+
member = value; \
30+
post_process; \
3131
}
3232

33-
#define OV_DEFINE_GETTER(type, getter, member, extra_qualifier) \
34-
type getter() extra_qualifier \
35-
{ \
36-
return member; \
37-
}
38-
39-
#define OV_DEFINE_CONST_GETTER(type, getter, member, extra_qualifier) \
40-
const type &getter() const extra_qualifier \
33+
#define OV_DEFINE_GETTER(value_type, getter, member, extra_qualifier) \
34+
value_type getter() extra_qualifier \
4135
{ \
4236
return member; \
4337
}
4438

45-
#define OV_DEFINE_SETTER_CONST_GETTER(type, setter, getter, member, extra_qualifier, pre_process, post_process) \
46-
OV_DEFINE_SETTER(type, setter, member, extra_qualifier, pre_process, post_process) \
47-
OV_DEFINE_CONST_GETTER(type, getter, member, extra_qualifier)
39+
#define OV_DEFINE_CONST_GETTER(value_type, getter, member, extra_qualifier) \
40+
const value_type &getter() const extra_qualifier \
41+
{ \
42+
return member; \
43+
}
44+
45+
#define OV_DEFINE_SETTER_CONST_GETTER(value_type, setter_return, setter, getter, member, extra_qualifier, pre_process, post_process) \
46+
OV_DEFINE_SETTER(value_type, setter_return, setter, member, extra_qualifier, pre_process, post_process) \
47+
OV_DEFINE_CONST_GETTER(value_type, getter, member, extra_qualifier)

src/projects/base/ovlibrary/url.cpp

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,14 @@ namespace ov
118118
return result_string;
119119
}
120120

121-
void Url::SetPath(const ov::String &path)
121+
bool Url::SetPath(const ov::String &path)
122122
{
123123
_path = path;
124124

125+
_file = "";
126+
_stream = "";
127+
_app = "";
128+
125129
// split <path> to /<app>/<stream>/<file> (4 tokens)
126130
auto tokens = _path.Split("/");
127131

@@ -142,6 +146,8 @@ namespace ov
142146
// Nothing to do
143147
break;
144148
}
149+
150+
return true;
145151
}
146152

147153
bool Url::ParseFromSource()
@@ -186,9 +192,12 @@ namespace ov
186192
{
187193
auto object = std::make_shared<Url>();
188194

189-
object->SetSource(url);
195+
if (object->SetSource(url))
196+
{
197+
return object;
198+
}
190199

191-
return object;
200+
return nullptr;
192201
}
193202

194203
bool Url::PushBackQueryKey(const ov::String &key)
@@ -268,37 +277,37 @@ namespace ov
268277
return true;
269278
}
270279

271-
void Url::UpdateUrl(bool is_source_updated)
280+
bool Url::UpdateUrl(bool is_source_updated)
272281
{
273282
if (is_source_updated)
274283
{
275284
// Get component values from the _source
276-
ParseFromSource();
285+
return ParseFromSource();
277286
}
278-
else
279-
{
280-
_source = ToUrlString();
281287

282-
_path = "";
288+
_source = ToUrlString();
283289

284-
if (_app.IsEmpty() == false)
285-
{
286-
_path.Append("/");
287-
_path.Append(_app);
288-
}
290+
_path = "";
289291

290-
if (_stream.IsEmpty() == false)
291-
{
292-
_path.Append("/");
293-
_path.Append(_stream);
294-
}
292+
if (_app.IsEmpty() == false)
293+
{
294+
_path.Append("/");
295+
_path.Append(_app);
296+
}
295297

296-
if (_file.IsEmpty() == false)
297-
{
298-
_path.Append("/");
299-
_path.Append(_file);
300-
}
298+
if (_stream.IsEmpty() == false)
299+
{
300+
_path.Append("/");
301+
_path.Append(_stream);
301302
}
303+
304+
if (_file.IsEmpty() == false)
305+
{
306+
_path.Append("/");
307+
_path.Append(_file);
308+
}
309+
310+
return true;
302311
}
303312

304313
void Url::ParseQueryIfNeeded() const
@@ -383,6 +392,8 @@ namespace ov
383392
{
384393
_source = other._source;
385394
_scheme = other._scheme;
395+
_id = other._id;
396+
_password = other._password;
386397
_host = other._host;
387398
_port = other._port;
388399
_path = other._path;
@@ -401,6 +412,8 @@ namespace ov
401412
{
402413
_source = other._source;
403414
_scheme = other._scheme;
415+
_id = other._id;
416+
_password = other._password;
404417
_host = other._host;
405418
_port = other._port;
406419
_path = other._path;

src/projects/base/ovlibrary/url.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ namespace ov
2323
// <scheme>://<host>[:<port>][/<path/to/resource>][?<query string>]
2424
static std::shared_ptr<Url> Parse(const ov::String &url);
2525

26-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetSource, Source, _source, , , UpdateUrl(true))
27-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetScheme, Scheme, _scheme, , , UpdateUrl(false))
28-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetHost, Host, _host, , , UpdateUrl(false))
29-
OV_DEFINE_SETTER_CONST_GETTER(uint32_t, SetPort, Port, _port, , , UpdateUrl(false))
26+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetSource, Source, _source, , , return UpdateUrl(true))
27+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetScheme, Scheme, _scheme, , , return UpdateUrl(false))
28+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetHost, Host, _host, , , return UpdateUrl(false))
29+
OV_DEFINE_SETTER_CONST_GETTER(uint32_t, bool, SetPort, Port, _port, , , return UpdateUrl(false))
3030
OV_DEFINE_CONST_GETTER(ov::String, Path, _path, )
31-
void SetPath(const ov::String &path);
32-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetApp, App, _app, , , UpdateUrl(false))
33-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetStream, Stream, _stream, , , UpdateUrl(false))
34-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetFile, File, _file, , , UpdateUrl(false))
35-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetId, Id, _id, , , UpdateUrl(false))
36-
OV_DEFINE_SETTER_CONST_GETTER(ov::String, SetPassword, Password, _password, , , UpdateUrl(false))
31+
bool SetPath(const ov::String &path);
32+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetApp, App, _app, , , return UpdateUrl(false))
33+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetStream, Stream, _stream, , , return UpdateUrl(false))
34+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetFile, File, _file, , , return UpdateUrl(false))
35+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetId, Id, _id, , , return UpdateUrl(false))
36+
OV_DEFINE_SETTER_CONST_GETTER(ov::String, bool, SetPassword, Password, _password, , , return UpdateUrl(false))
3737

3838
bool HasQueryString() const;
3939
const ov::String &Query() const;
@@ -57,7 +57,7 @@ namespace ov
5757

5858
protected:
5959
bool ParseFromSource();
60-
void UpdateUrl(bool is_source_updated);
60+
bool UpdateUrl(bool is_source_updated);
6161

6262
private:
6363
void ParseQueryIfNeeded() const;

0 commit comments

Comments
 (0)