Skip to content

Commit 5bfc4f3

Browse files
Jessie-JY2728adazem009
authored andcommitted
Fix #493: Ignore leading/trailing spaces in url (#494)
1 parent 16ab889 commit 5bfc4f3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/internal/projecturl.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ ProjectUrl::ProjectUrl(const std::string &url)
2222

2323
if (parts.empty())
2424
return;
25+
26+
// trim leading whitespaces
27+
str = parts.front();
28+
str.erase(str.begin(), std::find_if(str.begin(), str.end(), [](unsigned char ch) {
29+
return !std::isspace(ch);
30+
}));
31+
parts[0] = str;
32+
33+
// trim trailing whitespaces
34+
str = parts.back();
35+
str.erase(std::find_if(str.rbegin(), str.rend(), [](int ch){
36+
return !std::isspace(ch);
37+
}).base(), str.end());
38+
parts[parts.size() - 1] = str;
2539

2640
// Remove empty parts
2741
parts.erase(std::remove(parts.begin(), parts.end(), ""), parts.end());

test/network/projecturl_test.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,23 @@ TEST(ProjectUrlTest, Parse)
5959
ASSERT_FALSE(url.isProjectUrl());
6060
ASSERT_TRUE(url.projectId().empty());
6161
}
62+
63+
{
64+
ProjectUrl url(" https:/scratch.mit.edu/projects/886166351");
65+
ASSERT_TRUE(url.isProjectUrl());
66+
ASSERT_EQ(url.projectId(), "886166351");
67+
}
68+
69+
{
70+
ProjectUrl url("https:/scratch.mit.edu/projects/886166351 ");
71+
ASSERT_TRUE(url.isProjectUrl());
72+
ASSERT_EQ(url.projectId(), "886166351");
73+
}
74+
75+
{
76+
ProjectUrl url(" https:/scratch.mit.edu/projects/886166351 ");
77+
ASSERT_TRUE(url.isProjectUrl());
78+
ASSERT_EQ(url.projectId(), "886166351");
79+
}
80+
6281
}

0 commit comments

Comments
 (0)