Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] URL's that exactly match a registried regex pattern dispatch to that registered resource #308

Open
1 task done
bcsgh opened this issue Apr 6, 2023 · 2 comments
Assignees
Labels
bug Confirmed bugs or reports that are very likely to be bugs.

Comments

@bcsgh
Copy link
Contributor

bcsgh commented Apr 6, 2023

Prerequisites

Description

This test here is in error because that map is populated with the URL including the regexp pattern.

This results in a url that includes the same text as the regex pattern matching, even if that text isn't matched by the regex.

Steps to Reproduce

Add the following to test/integ/basic.cpp (2ea297f):

LT_BEGIN_AUTO_TEST(basic_suite, regex_url_exact_match)
    ok_resource resource;
    ws->register_resource("/foo/{v|[a-z]}/bar", &resource);
    curl_global_init(CURL_GLOBAL_ALL);

    string s;
    CURL *curl = curl_easy_init();
    CURLcode res;

    // Exact string match for the registered pattern 
    curl_easy_setopt(curl, CURLOPT_URL, "localhost:8080/foo/{v|[a-z]}/bar/");

    curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writefunc);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s);
    res = curl_easy_perform(curl);
    LT_ASSERT_EQ(res, 0);

    int64_t http_code = 0;
    curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE , &http_code);
    LT_ASSERT_EQ(http_code, 404);    /// <<<<<<<<<<<<< This fails: 200!=404
    curl_easy_cleanup(curl);
LT_END_AUTO_TEST(regex_url_exact_match)

Expected behavior: HTTP 404 (assuming the RE pattern doesn't match itself).

Actual behavior: HTTP 200

Reproduces how often: 100%

Versions

Current master branch

@bcsgh bcsgh added the bug Confirmed bugs or reports that are very likely to be bugs. label Apr 6, 2023
@bcsgh bcsgh assigned etr Apr 6, 2023
bcsgh added a commit to bcsgh/libhttpserver that referenced this issue Apr 6, 2023
etr pushed a commit that referenced this issue Apr 10, 2023
* Add some test of how registired resources interactwith eachother.

* Add a test case for #308

* Make more picky warning settings happy.

* Make lint happy.

* Correct a test cases for -DCASE_INSENSITIVE

Also add a comment that the non `-DCASE_INSENSITIVE` testcases is probably wrong.

* Make lint happy about the TODO

Really this should be assigned to an issue report, not a person, because nobody has agreed to fix it yet.
@etr
Copy link
Owner

etr commented Jul 1, 2023

@bcsgh I think your change fixes this issue, right?

@bcsgh
Copy link
Contributor Author

bcsgh commented Jul 1, 2023

I fixed some other issues. This one is still there because I gave up before firing out how to solve it (and because I'm not using that type of pattern):

https://github.com/etr/libhttpserver/blob/master/test/integ/basic.cpp#L1429-L1433
The #if 0 at the above should be switched to test for the correct behavior rather than demoing the wrong one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed bugs or reports that are very likely to be bugs.
Projects
None yet
Development

No branches or pull requests

2 participants