Compare commits

..

3 Commits

Author SHA1 Message Date
Archilocos 6d179c3a25
Merge f361527459 into 595c6d275e 2023-10-03 23:46:55 +01:00
Fufu Fang 595c6d275e
Remove spurious code
Remote spurious code flagged by 8451da6ac7,
which was introduced by e76b079fe6
Closes https://github.com/fangfufu/httpdirfs/issues/124
2023-10-03 23:10:24 +01:00
chrysn bd33966337 Allow leading `./` segments in links 2023-10-02 23:44:18 +01:00
1 changed files with 25 additions and 18 deletions

View File

@ -408,20 +408,6 @@ static void HTML_to_LinkTable(const char *url, GumboNode *node,
* This is to prevent duplicated link, if an Apache server has the
* IconsAreLinks option.
*/
/* The following four lines of code have no effect so I've commented
them out. I'm not removing them entirely because it's possible the
original intent was to do a check of some sort here and it's an
error that this check wasn't fully implemented, in which case this
commented out code and the comment above it should serve as a
reminder to whoever originally wrote it that there's something
unfinished here that needs to be finished.
*/
/*
size_t comp_len = strnlen(link_url, MAX_FILENAME_LEN);
if (type == LINK_DIR) {
comp_len--;
}
*/
if (((type == LINK_DIR) || (type == LINK_UNINITIALISED_FILE)) &&
!linknames_equal(linktbl->links[linktbl->num - 1]->linkname,
link_url)) {
@ -1115,12 +1101,33 @@ long path_download(const char *path, char *output_buf, size_t req_size,
static void make_link_relative(const char *page_url, char *link_url)
{
/*
Some servers make the links to subdirectories absolute, but our code
expects them to be relative, so change the contents of link_url as
needed to accommodate that.
Some servers make the links to subdirectories absolute (in URI terms:
path-absolute), but our code expects them to be relative (in URI terms:
path-noscheme), so change the contents of link_url as needed to
accommodate that.
Also, some servers serve their links as `./name`. This is helpful to
them because it is the only way to express relative references when the
first new path segment of the target contains an unescaped colon (`:`),
eg in `./6:1-balun.png`. While stripping the ./ strictly speaking
reintroduces that ambiguity, it is of little practical concern in this
implementation, as full URI link targets are filtered by their number of
slashes anyway. In URI terms, this converts path-noscheme with a leading
`.` segment into path-noscheme or path-rootless without that segment.
*/
if (link_url[0] == '.' && link_url[1] == '/') {
memmove(link_url, link_url + 2, strlen(link_url) - 1);
return;
}
if (link_url[0] != '/') {
/* Already relative, nothing to do here! */
/* Already relative, nothing to do here!
(Full URIs, eg. `http://example.com/path`, pass through here
unmodified, but those are classified in different LinkTypes later
anyway).
*/
return;
}