Fix URL detection not working for urls of the form scheme:///url
Fixes #2292
This commit is contained in:
parent
96f3253e6d
commit
43326c9bd0
@ -36,6 +36,9 @@ To update |kitty|, :doc:`follow the instructions <binary>`.
|
|||||||
- ``goto_tab`` now maps numbers larger than the last tab to the last tab
|
- ``goto_tab`` now maps numbers larger than the last tab to the last tab
|
||||||
(:iss:`2291`)
|
(:iss:`2291`)
|
||||||
|
|
||||||
|
- Fix URL detection not working for urls of the form scheme:///url
|
||||||
|
(:iss:`2292`)
|
||||||
|
|
||||||
|
|
||||||
0.15.1 [2019-12-21]
|
0.15.1 [2019-12-21]
|
||||||
--------------------
|
--------------------
|
||||||
|
|||||||
@ -50,7 +50,7 @@ cell_text(CPUCell *cell) {
|
|||||||
// URL detection {{{
|
// URL detection {{{
|
||||||
|
|
||||||
static const char* url_prefixes[4] = {"https", "http", "file", "ftp"};
|
static const char* url_prefixes[4] = {"https", "http", "file", "ftp"};
|
||||||
static size_t url_prefix_lengths[sizeof(url_prefixes)/sizeof(url_prefixes[0])] = {0};
|
static size_t url_prefix_lengths[arraysz(url_prefixes)] = {0};
|
||||||
|
|
||||||
static inline index_type
|
static inline index_type
|
||||||
find_colon_slash(Line *self, index_type x, index_type limit) {
|
find_colon_slash(Line *self, index_type x, index_type limit) {
|
||||||
@ -79,7 +79,7 @@ find_colon_slash(Line *self, index_type x, index_type limit) {
|
|||||||
break;
|
break;
|
||||||
case SECOND_SLASH:
|
case SECOND_SLASH:
|
||||||
if (ch == ':') return pos;
|
if (ch == ':') return pos;
|
||||||
state = ANY;
|
state = ch == '/' ? SECOND_SLASH : ANY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pos--;
|
pos--;
|
||||||
@ -100,9 +100,9 @@ prefix_matches(Line *self, index_type at, const char* prefix, index_type prefix_
|
|||||||
static inline bool
|
static inline bool
|
||||||
has_url_prefix_at(Line *self, index_type at, index_type min_prefix_len, index_type *ans) {
|
has_url_prefix_at(Line *self, index_type at, index_type min_prefix_len, index_type *ans) {
|
||||||
if (UNLIKELY(!url_prefix_lengths[0])) {
|
if (UNLIKELY(!url_prefix_lengths[0])) {
|
||||||
for (index_type i = 0; i < sizeof(url_prefixes)/sizeof(url_prefixes[0]); i++) url_prefix_lengths[i] = strlen(url_prefixes[i]);
|
for (index_type i = 0; i < arraysz(url_prefixes); i++) url_prefix_lengths[i] = strlen(url_prefixes[i]);
|
||||||
}
|
}
|
||||||
for (index_type i = 0; i < sizeof(url_prefixes)/sizeof(url_prefixes[0]); i++) {
|
for (index_type i = 0; i < arraysz(url_prefixes); i++) {
|
||||||
index_type prefix_len = url_prefix_lengths[i];
|
index_type prefix_len = url_prefix_lengths[i];
|
||||||
if (at < prefix_len || prefix_len < min_prefix_len) continue;
|
if (at < prefix_len || prefix_len < min_prefix_len) continue;
|
||||||
if (prefix_matches(self, at, url_prefixes[i], prefix_len)) { *ans = at - prefix_len; return true; }
|
if (prefix_matches(self, at, url_prefixes[i], prefix_len)) { *ans = at - prefix_len; return true; }
|
||||||
|
|||||||
@ -238,6 +238,9 @@ class TestDataTypes(BaseTest):
|
|||||||
lf.set_text(t, 0, len(t), C())
|
lf.set_text(t, 0, len(t), C())
|
||||||
return lf
|
return lf
|
||||||
|
|
||||||
|
l0 = create('file:///etc/test')
|
||||||
|
self.ae(l0.url_start_at(0), 0)
|
||||||
|
|
||||||
for trail in '.,]>)\\':
|
for trail in '.,]>)\\':
|
||||||
lx = create("http://xyz.com" + trail)
|
lx = create("http://xyz.com" + trail)
|
||||||
self.ae(lx.url_end_at(0), len(lx) - 2)
|
self.ae(lx.url_end_at(0), len(lx) - 2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user