From 4e6e2937713766a29918a8f327bf285cbc8954f7 Mon Sep 17 00:00:00 2001 From: Matt Rose Date: Mon, 11 Mar 2024 15:17:51 -0400 Subject: [PATCH] Properly parse file:/// URIs Previously, file URIs were lumped in with full uris that would be used for HTTP, FTP, etc. This caused file:/// uri parser to ignore any file with a root dir that had a character that was not a valid hostname character to be ignored. --- terminatorlib/terminal.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/terminatorlib/terminal.py b/terminatorlib/terminal.py index c34b7ab6..2aaf58d7 100644 --- a/terminatorlib/terminal.py +++ b/terminatorlib/terminal.py @@ -300,6 +300,7 @@ class Terminal(Gtk.VBox): registry.load_plugins(force) def _add_regex(self, name, re): + dbg(f"adding regex: {re}") match = -1 if regex.FLAGS_PCRE2: try: @@ -323,19 +324,23 @@ class Terminal(Gtk.VBox): passchars = "-A-Za-z0-9,?;.:/!%$^*&~\"#'" hostchars = r"-A-Za-z0-9:\[\]" pathchars = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%'" - schemes = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:|ssh:)" + schemes = "(news:|telnet:|nntp:|https?:|ftps?:|webcal:|ssh:)" user = "[" + userchars + "]+(:[" + passchars + "]+)?" urlpath = "/[" + pathchars + "]*[^]'.}>) \t\r\n,\\\"]" lboundry = "\\b" rboundry = "\\b" + re = (lboundry + "file:/" + "//?(:[0-9]+)?(" + urlpath + ")" + + rboundry + "/?") + self._add_regex('file', re) + re = (lboundry + schemes + "//(" + user + "@)?[" + hostchars +".]+(:[0-9]+)?(" + urlpath + ")?" + rboundry + "/?") self._add_regex('full_uri', re) - if self.matches['full_uri'] == -1: + if self.matches['full_uri'] == -1 or self.matches['file'] == -1: err ('Terminal::update_url_matches: Failed adding URL matches') else: re = (lboundry +