Mercurial > octave
changeset 29214:45abff4199d8 stable
stat: Improve regular expression for UNC roots on Windows (bug #59706).
* liboctave/system/file-stat.cc (file_stat::update_internal): Improve regular
expression for UNC roots on Windows. Add simple checks to avoid using the
regular expression for non-UNC paths.
author | Markus Mützel <markus.muetzel@gmx.de> |
---|---|
date | Mon, 21 Dec 2020 19:24:58 +0100 |
parents | e8819aa30715 |
children | 6e031c8ed59c 0180eaf55fd0 |
files | liboctave/system/file-stat.cc |
diffstat | 1 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/system/file-stat.cc Mon Dec 21 11:29:35 2020 +0100 +++ b/liboctave/system/file-stat.cc Mon Dec 21 19:24:58 2020 +0100 @@ -204,11 +204,13 @@ // If path is a root (like "C:" or "\\SERVER\share"), add a // trailing backslash. - // FIXME: Does this pattern match all possible UNC roots? - regexp pat (R"(^\\\\[\w-]*\\[\w-]*$)"); + // FIXME: This pattern does not match all possible UNC roots: + // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-dtyp/62e862f4-2a51-452e-8eeb-dc4ff5ee33cc + regexp pat (R"(^\\\\[\w.-]+\\[\w\$-]+$)"); if ((full_file_name.length () == 2 && full_file_name[1] == ':') - || pat.is_match (full_file_name)) - full_file_name += '\\'; + || (full_file_name.length () > 4 && full_file_name[0] == '\\' + && full_file_name[1] == '\\' && pat.is_match (full_file_name))) + full_file_name.push_back ('\\'); #endif const char *cname = full_file_name.c_str ();