[cmake-developers] [patch] One more pattern for extracting file name from URL

Ruslan Baratov ruslan_baratov at yahoo.com
Fri Jul 1 11:48:58 EDT 2016


On 01-Jul-16 15:58, Brad King wrote:
> On 07/01/2016 08:01 AM, Ruslan Baratov via cmake-developers wrote:
>> With attached patch it's possible to extract name from URLs like
>> 'https://.../archive.tar.gz?a=x&b=y'.
> Thanks.
>
>>           elseif(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
>> -          message(FATAL_ERROR "Could not extract tarball filename from url:\n  ${url}")
>> +          # Try: https://.../archive.tar.gz?a=x&b=y
>> +          string(REGEX MATCH "^.*/([^/]*)\\?.*$" match_result "${url}")
>> +          set(fname "${CMAKE_MATCH_1}")
>> +          if(NOT "${fname}" MATCHES "(\\.|=)(7z|tar|tar\\.bz2|tar\\.gz|tar\\.xz|tbz2|tgz|txz|zip)$")
>> +            message(FATAL_ERROR "Could not extract tarball filename from url:\n  ${url}")
>> +          endif()
> Please try to structure the logic right in the if/elseif part.
> Matching in those also sets `CMAKE_MATCH_*` variables so one
> does not need to double-match.
'elseif' part try to find 'archive.tar.gz' in '${fname}', then 
'string(REGEX' try to match it in '${url}'. There is no reusing of 
'CMAKE_MATCH_*'.

>
> Also, the `([^/]*)\\?.*` part of the regex should be more
> like `([^/?]*)\\?.*` to avoid eagerly matching early `?`.
We can't have question mark ('?') in path as far as I understand, it 
should be percent-encoded, will be |'%3F'.|||
https://en.wikipedia.org/wiki/Uniform_Resource_Locator#Syntax
https://en.wikipedia.org/wiki/Percent-encoding

Ruslo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160701/582a39dc/attachment.html>


More information about the cmake-developers mailing list