Skip to content

Commit a21cf9f

Browse files
author
Steve Hanson
committed
equiv fix for issue 1899
1 parent 12b88ef commit a21cf9f

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

include/rapidjson/uri.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class GenericUri {
6262
#endif
6363

6464
//! Copy constructor
65-
GenericUri(const GenericUri& rhs) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(rhs.allocator_), ownAllocator_() {
65+
GenericUri(const GenericUri& rhs) : uri_(), base_(), scheme_(), auth_(), path_(), query_(), frag_(), allocator_(), ownAllocator_() {
6666
*this = rhs;
6767
}
6868

@@ -101,19 +101,19 @@ class GenericUri {
101101
}
102102

103103
const Ch* GetString() const { return uri_; }
104-
SizeType GetStringLength() const { return internal::StrLen<Ch>(uri_); }
104+
SizeType GetStringLength() const { return uri_ == 0 ? 0 : internal::StrLen<Ch>(uri_); }
105105
const Ch* GetBaseString() const { return base_; }
106-
SizeType GetBaseStringLength() const { return internal::StrLen<Ch>(base_); }
106+
SizeType GetBaseStringLength() const { return base_ == 0 ? 0 : internal::StrLen<Ch>(base_); }
107107
const Ch* GetSchemeString() const { return scheme_; }
108-
SizeType GetSchemeStringLength() const { return internal::StrLen<Ch>(scheme_); }
108+
SizeType GetSchemeStringLength() const { return scheme_ == 0 ? 0 : internal::StrLen<Ch>(scheme_); }
109109
const Ch* GetAuthString() const { return auth_; }
110-
SizeType GetAuthStringLength() const { return internal::StrLen<Ch>(auth_); }
110+
SizeType GetAuthStringLength() const { return auth_ == 0 ? 0 : internal::StrLen<Ch>(auth_); }
111111
const Ch* GetPathString() const { return path_; }
112-
SizeType GetPathStringLength() const { return internal::StrLen<Ch>(path_); }
112+
SizeType GetPathStringLength() const { return path_ == 0 ? 0 : internal::StrLen<Ch>(path_); }
113113
const Ch* GetQueryString() const { return query_; }
114-
SizeType GetQueryStringLength() const { return internal::StrLen<Ch>(query_); }
114+
SizeType GetQueryStringLength() const { return query_ == 0 ? 0 : internal::StrLen<Ch>(query_); }
115115
const Ch* GetFragString() const { return frag_; }
116-
SizeType GetFragStringLength() const { return internal::StrLen<Ch>(frag_); }
116+
SizeType GetFragStringLength() const { return frag_ == 0 ? 0 : internal::StrLen<Ch>(frag_); }
117117

118118
#if RAPIDJSON_HAS_STDSTRING
119119
static String Get(const GenericUri& uri) { return String(uri.GetString(), uri.GetStringLength()); }

test/unittest/uritest.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ RAPIDJSON_DIAG_OFF(4822) // local class member function does not have a body
2929

3030
using namespace rapidjson;
3131

32+
TEST(Uri, DefaultConstructor) {
33+
typedef GenericUri<Value> UriType;
34+
UriType u;
35+
EXPECT_TRUE(u.GetSchemeString() == 0);
36+
EXPECT_TRUE(u.GetAuthString() == 0);
37+
EXPECT_TRUE(u.GetPathString() == 0);
38+
EXPECT_TRUE(u.GetBaseString() == 0);
39+
EXPECT_TRUE(u.GetQueryString() == 0);
40+
EXPECT_TRUE(u.GetFragString() == 0);
41+
EXPECT_TRUE(u.GetString() == 0);
42+
EXPECT_TRUE(u.GetSchemeStringLength() == 0);
43+
EXPECT_TRUE(u.GetAuthStringLength() == 0);
44+
EXPECT_TRUE(u.GetPathStringLength() == 0);
45+
EXPECT_TRUE(u.GetBaseStringLength() == 0);
46+
EXPECT_TRUE(u.GetQueryStringLength() == 0);
47+
EXPECT_TRUE(u.GetFragStringLength() == 0);
48+
EXPECT_TRUE(u.GetStringLength() == 0);
49+
}
50+
51+
3252
TEST(Uri, Parse) {
3353
typedef GenericUri<Value, MemoryPoolAllocator<> > UriType;
3454
MemoryPoolAllocator<CrtAllocator> allocator;
@@ -256,6 +276,27 @@ TEST(Uri, Parse_UTF16) {
256276
EXPECT_TRUE(u.GetFragStringLength() == len);
257277
}
258278

279+
TEST(Uri, CopyConstructor) {
280+
typedef GenericUri<Value> UriType;
281+
CrtAllocator allocator;
282+
283+
UriType u("http://auth/path/xxx?query#frag", &allocator);
284+
UriType u2(u);
285+
EXPECT_TRUE(u == u2);
286+
EXPECT_NE(&u.GetAllocator(), &u2.GetAllocator());
287+
}
288+
289+
TEST(Uri, Assignment) {
290+
typedef GenericUri<Value> UriType;
291+
CrtAllocator allocator;
292+
293+
UriType u("http://auth/path/xxx?query#frag", &allocator);
294+
UriType u2;
295+
u2 = u;
296+
EXPECT_TRUE(u == u2);
297+
EXPECT_NE(&u.GetAllocator(), &u2.GetAllocator());
298+
}
299+
259300
TEST(Uri, Resolve) {
260301
typedef GenericUri<Value> UriType;
261302
CrtAllocator allocator;
@@ -648,6 +689,15 @@ TEST(Uri, Match) {
648689
EXPECT_FALSE(d.Match(a));
649690
}
650691

692+
TEST(Uri, Issue1899) {
693+
typedef GenericUri<Value, MemoryPoolAllocator<> > UriType;
694+
695+
UriType base = UriType("http://auth/path/#frag");
696+
UriType ref = UriType("http://newauth/newpath#newfrag");
697+
UriType res = ref.Resolve(base);
698+
EXPECT_TRUE(StrCmp(res.GetString(), "http://newauth/newpath#newfrag") == 0);
699+
}
700+
651701
#if defined(_MSC_VER) || defined(__clang__)
652702
RAPIDJSON_DIAG_POP
653703
#endif

0 commit comments

Comments
 (0)