]> granicus.if.org Git - vim/commitdiff
patch 8.2.3153: URLs with a dash in the scheme are not recognized v8.2.3153
authorTsuyoshi CHO <Tsuyoshi.CHO@Gmail.com>
Sun, 11 Jul 2021 19:51:17 +0000 (21:51 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 11 Jul 2021 19:51:17 +0000 (21:51 +0200)
Problem:    URLs with a dash in the scheme are not recognized.
Solution:   Allow for a scheme with a dash, but not at the start or end.
            (Tsuyoshi CHO, closes #8299)

src/misc1.c
src/testdir/test_buffer.vim
src/version.c

index d112d9b95dce2ad9a0435ed3e978bc410298edbb..554f10b18697b39c471d9e9583d5ddb7fdb43063 100644 (file)
@@ -2600,8 +2600,8 @@ path_is_url(char_u *p)
 }
 
 /*
- * Check if "fname" starts with "name://".  Return URL_SLASH if it does.
- * Return URL_BACKSLASH for "name:\\".
+ * Check if "fname" starts with "name://" or "name:\\".
+ * Return URL_SLASH for "name://", URL_BACKSLASH for "name:\\".
  * Return zero otherwise.
  */
     int
@@ -2609,7 +2609,22 @@ path_with_url(char_u *fname)
 {
     char_u *p;
 
-    for (p = fname; isalpha(*p); ++p)
+    // We accept alphabetic characters and a dash in scheme part.
+    // RFC 3986 allows for more, but it increases the risk of matching
+    // non-URL text.
+
+    // first character must be alpha
+    if (!isalpha(*fname))
+       return 0;
+
+    // check body: alpha or dash
+    for (p = fname; (isalpha(*p) || (*p == '-')); ++p)
        ;
+
+    // check last char is not a dash
+    if (p[-1] == '-')
+       return 0;
+
+    // "://" or ":\\" must follow
     return path_is_url(p);
 }
index 960a760ebd473b59f7e622902552c4a46a302993..aa2fe7ac6443eed3228f8131552e50ea1f9a7bd7 100644 (file)
@@ -381,6 +381,35 @@ func Test_balt()
   call assert_equal('OtherBuffer', bufname())
 endfunc
 
+" Test for buffer match URL(scheme) check
+" scheme is alpha and inner hyphen only.
+func Test_buffer_scheme()
+  CheckMSWindows
+
+  set noshellslash
+  %bwipe!
+  let bufnames = [
+    \ #{id: 'b0', name: 'test://xyz/foo/b0'    , match: 1},
+    \ #{id: 'b1', name: 'test+abc://xyz/foo/b1', match: 0},
+    \ #{id: 'b2', name: 'test_abc://xyz/foo/b2', match: 0},
+    \ #{id: 'b3', name: 'test-abc://xyz/foo/b3', match: 1},
+    \ #{id: 'b4', name: '-test://xyz/foo/b4'   , match: 0},
+    \ #{id: 'b5', name: 'test-://xyz/foo/b5'   , match: 0},
+    \]
+  for buf in bufnames
+    new `=buf.name`
+    if buf.match
+      call assert_equal(buf.name,    getbufinfo(buf.id)[0].name)
+    else
+      " slashes will have become backslashes
+      call assert_notequal(buf.name, getbufinfo(buf.id)[0].name)
+    endif
+    bwipe
+  endfor
+
+  set shellslash&
+endfunc
+
 " Test for the 'maxmem' and 'maxmemtot' options
 func Test_buffer_maxmem()
   " use 1KB per buffer and 2KB for all the buffers
index 21394aa1a7fff5a999523d7fbe679858063732fc..940c7192fa402846e8da5ed04d4b673a5877d611 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3153,
 /**/
     3152,
 /**/