Skip to content

Commit adc93ac

Browse files
committed
test: add more edge cases
1 parent 22ef225 commit adc93ac

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/url-setters.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ namespace ada {
5050
void url::set_search(const std::string_view input) {
5151
if (input.empty()) {
5252
query = std::nullopt;
53-
if (has_opaque_path) {
54-
size_t non_whitespace_location = path.find_first_of(' ');
55-
if (non_whitespace_location != std::string_view::npos) {
56-
path = path.substr(0, non_whitespace_location);
57-
}
53+
54+
// Potentially strip trailing spaces from an opaque path
55+
if (!has_opaque_path || fragment.has_value()) return;
56+
57+
size_t non_whitespace_location = path.find_first_of(' ');
58+
if (non_whitespace_location != std::string_view::npos) {
59+
path = path.substr(0, non_whitespace_location);
5860
}
5961
return;
6062
}

tests/basic_tests.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,26 @@ bool nodejs2() {
150150
TEST_SUCCEED()
151151
}
152152

153+
bool nodejs3() {
154+
TEST_START()
155+
auto url = ada::parse("data:space ?test#test");
156+
TEST_ASSERT(url->get_search(), "?test", "search is not equal");
157+
url->set_search("");
158+
TEST_ASSERT(url->get_search(), "", "search should have been empty");
159+
TEST_ASSERT(url->get_pathname(), "space ", "pathname should have been 'space' without trailing spaces");
160+
TEST_ASSERT(url->get_href(), "data:space #test", "href is not equal");
161+
TEST_SUCCEED()
162+
}
163+
153164
int main() {
154165
bool success = set_host_should_return_false_sometimes()
155166
&& set_host_should_return_true_sometimes()
156167
&& set_hostname_should_return_false_sometimes()
157168
&& set_hostname_should_return_true_sometimes()
158169
&& readme1() && readme2() && readme3()
159170
&& readme4() && readme5() && readme6()
160-
&& readme7() && nodejs1() && nodejs2();
171+
&& readme7() && nodejs1() && nodejs2()
172+
&& nodejs3();
161173
if(success) { return EXIT_SUCCESS; }
162174
return EXIT_FAILURE;
163175
}

0 commit comments

Comments
 (0)