Fix detection of URLs in HTML source code (URLs inside quotes)

Fixes #785
This commit is contained in:
Kovid Goyal
2018-08-03 12:28:23 +05:30
parent 8d20dbe81d
commit e5a720c6fa
6 changed files with 49 additions and 17 deletions

View File

@@ -132,10 +132,11 @@ line_url_start_at(Line *self, index_type x) {
}
index_type
line_url_end_at(Line *self, index_type x, bool check_short) {
line_url_end_at(Line *self, index_type x, bool check_short, char_type sentinel) {
index_type ans = x;
if (x >= self->xnum || (check_short && self->xnum <= MIN_URL_LEN + 3)) return 0;
while (ans < self->xnum && is_url_char(self->cpu_cells[ans].ch)) ans++;
if (sentinel) { while (ans < self->xnum && self->cpu_cells[ans].ch != sentinel && is_url_char(self->cpu_cells[ans].ch)) ans++; }
else { while (ans < self->xnum && is_url_char(self->cpu_cells[ans].ch)) ans++; }
if (ans) ans--;
while (ans > x && can_strip_from_end_of_url(self->cpu_cells[ans].ch)) ans--;
return ans;
@@ -148,9 +149,11 @@ url_start_at(Line *self, PyObject *x) {
}
static PyObject*
url_end_at(Line *self, PyObject *x) {
url_end_at(Line *self, PyObject *args) {
#define url_end_at_doc "url_end_at(x) -> Return the end cell number for a URL containing x or 0 if not found"
return PyLong_FromUnsignedLong((unsigned long)line_url_end_at(self, PyLong_AsUnsignedLong(x), true));
unsigned int x, sentinel = 0;
if (!PyArg_ParseTuple(args, "I|I", &x, &sentinel)) return NULL;
return PyLong_FromUnsignedLong((unsigned long)line_url_end_at(self, x, true, sentinel));
}
// }}}
@@ -560,7 +563,7 @@ static PyMethodDef methods[] = {
METHOD(is_continued, METH_NOARGS)
METHOD(width, METH_O)
METHOD(url_start_at, METH_O)
METHOD(url_end_at, METH_O)
METHOD(url_end_at, METH_VARARGS)
METHOD(sprite_at, METH_O)
{NULL} /* Sentinel */