Check if a slash-prefixed string looks like a REST API path.
| 2070 | |
| 2071 | // Check if a slash-prefixed string looks like a REST API path. |
| 2072 | static bool is_rest_path(const char *s, int len) { |
| 2073 | if (is_filesystem_path(s, len)) { |
| 2074 | return false; |
| 2075 | } |
| 2076 | if (len > SKIP_ONE && s[len - SKIP_ONE] == '/') { |
| 2077 | return false; /* regex pattern */ |
| 2078 | } |
| 2079 | if (s[SKIP_ONE] == '^') { |
| 2080 | return false; /* regex */ |
| 2081 | } |
| 2082 | if (len == SKIP_ONE || (len == PAIR_LEN && s[SKIP_ONE] == '/')) { |
| 2083 | return false; /* bare / or // */ |
| 2084 | } |
| 2085 | if (s[SKIP_ONE] == '.') { |
| 2086 | return false; /* relative path */ |
| 2087 | } |
| 2088 | for (int i = SKIP_ONE; i < len && i < MAX_ROUTE_SCAN; i++) { |
| 2089 | char c = s[i]; |
| 2090 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) { |
| 2091 | return true; |
| 2092 | } |
| 2093 | } |
| 2094 | return false; |
| 2095 | } |
| 2096 | |
| 2097 | static bool is_url_like(const char *s, int len) { |
| 2098 | if (len < MIN_ROUTE_LEN) { |
no test coverage detected