aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog1
-rw-r--r--dpi/file.c35
-rw-r--r--src/uicmd.cc2
3 files changed, 29 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a8e09cf..b1b00247 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -57,6 +57,7 @@ dillo-3.1 [not released yet]
- Switch tabs using the mouse wheel by default. Use the new option
scroll_switches_tabs to disable the behavior.
- Fix OpenSSL handling of unexpected EOF without close notify alert.
+ - Expand home tilde '~' in the file plugin.
Patches: Rodrigo Arias Mallo <rodarima@gmail.com>
-----------------------------------------------------------------------------
diff --git a/dpi/file.c b/dpi/file.c
index a0990c43..f8415101 100644
--- a/dpi/file.c
+++ b/dpi/file.c
@@ -2,6 +2,7 @@
* File: file.c :)
*
* Copyright (C) 2000-2007 Jorge Arellano Cid <jcid@dillo.org>
+ * Copyright (C) 2024 Rodrigo Arias Mallo <rodarima@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -138,7 +139,7 @@ static const char *File_get_content_type_from_data(void *Data, size_t Size)
char *p = Data;
size_t i, non_ascci;
- _MSG("File_get_content_type_from_data:: Size = %d\n", Size);
+ _MSG("File_get_content_type_from_data:: Size = %zu\n", Size);
/* HTML try */
for (i = 0; i < Size && dIsspace(p[i]); ++i);
@@ -790,6 +791,7 @@ static int File_parse_hex_octet(const char *s)
/*
* Make a file URL into a human (and machine) readable path.
+ * The home tile '~' character is expanded from the value of $HOME.
* The idea is to always have a path that starts with only one slash.
* Embedded slashes are ignored.
*/
@@ -797,16 +799,35 @@ static char *File_normalize_path(const char *orig)
{
char *str = (char *) orig, *basename = NULL, *ret = NULL, *p;
- dReturn_val_if (orig == NULL, ret);
+ if (str == NULL)
+ return NULL;
- /* Make sure the string starts with "file:/" */
- if (dStrnAsciiCasecmp(str, "file:/", 5) != 0)
+ /* Make sure the string starts with "file:" */
+ if (dStrnAsciiCasecmp(str, "file:", 5))
return ret;
- str += 5;
- /* Skip "localhost" */
- if (dStrnAsciiCasecmp(str, "//localhost/", 12) == 0)
+ str += 5; /* skip "file:" */
+
+ Dstr *tmp = dStr_sized_new(32);
+
+ if (str[0] == '~' && (str[1] == '/' || str[1] == '\0')) {
+ /* Expand home tilde "~" into "/home/userxyz" */
+ const char *home = getenv("HOME");
+ if (home == NULL || home[0] == '\0') {
+ _MSG("cannot get home path from the environment variable HOME\n");
+ return NULL;
+ }
+ /* Add separator if needed */
+ char *sep = home[strlen(home) - 1] == '/' ? "" : "/";
+ char *next = str + 1;
+ while (*next == '/')
+ next++;
+ dStr_sprintf(tmp, "%s%s%s", home, sep, next);
+ str = tmp->str;
+ } else if (dStrnAsciiCasecmp(str, "//localhost/", 12) == 0) {
+ /* Skip "//localhost" */
str += 11;
+ }
/* Skip packed slashes, and leave just one */
while (str[0] == '/' && str[1] == '/')
diff --git a/src/uicmd.cc b/src/uicmd.cc
index e153ba70..5eb64b7b 100644
--- a/src/uicmd.cc
+++ b/src/uicmd.cc
@@ -730,8 +730,6 @@ void a_UIcmd_open_urlstr(void *vbw, const char *urlstr)
ch = new_urlstr[5];
if (!ch || ch == '.') {
url = a_Url_new(Paths::getOldWorkingDir(), "file:");
- } else if (ch == '~') {
- url = a_Url_new(dGethomedir(), "file:");
} else {
url = a_Url_new(new_urlstr, "file:");
}