Skip to content

Commit

Permalink
[12_23] length of url protocol >= 2
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii authored Dec 10, 2023
1 parent 5176da4 commit 3c0502a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion System/Classes/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ url_general (string name, int type= URL_SYSTEM) {
array<string> tokens = tokenize (name, "://");
string protocol= tokens[0];
string path = tokens[1];
if (N (tokens) == 2 && is_alphanum (protocol)) {
if (N (tokens) == 2 && is_alphanum (protocol) && N (protocol) >= 2) {
if (protocol == "file") return file_url (path);
if (protocol == "http") return http_url (path);
if (protocol == "https") return https_url (path);
Expand Down
3 changes: 3 additions & 0 deletions tests/System/Classes/url_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ TEST_CASE ("unknown protocol like zotero") {
url tmfs_u= url_system ("tmfs://git/status");
string_eq (tmfs_u.protocol (), "tmfs");
CHECK (!is_or (tmfs_u));

url c_u= url_system ("C://Program Files/MoganResearch");
string_neq (c_u.protocol (), "C");
}

TEST_MEMORY_LEAK_ALL
8 changes: 8 additions & 0 deletions tests/lolly_doctests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ string_eq (string left, string right) {
CHECK_EQ (left == right, true);
}

inline void
string_neq (string left, string right) {
if (left == right) {
cout << "same: " << left << LF;
}
CHECK_EQ (left != right, true);
}

#define TEST_MEMORY_LEAK_ALL \
TEST_CASE ("test memory leak above") { CHECK_EQ (mem_used (), mem_lolly); }

Expand Down

0 comments on commit 3c0502a

Please sign in to comment.