Skip to contentSkip to conversation

wget.py: support for semi-colons in URL

PATCH In review Juro Bystricky 5 participants 11 messages Jul 25, 2015 – Jul 29, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 wget.py: support for semi-colons in URL

Some URLs contain semi-colons. For example, some GIT repositories support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

This patch allows using of semi-colons in URLs: ';;' (double semi-colon) in SRC_URI is processed as a single semi-colon that is a part of a URL name. For example, the above URL would become:

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47"

Note that it is not possible to determine the name of the downloaded file from URL alone. The onus to specify the proper name is on the user, via the parameter 'downloadfilename':

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=myfile.tar.gz"

---
 bitbake/lib/bb/fetch2/wget.py | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
bitbake/lib/bb/fetch2/wget.py +15 -1
index 425b6b9..a623b83 100644
@@ -80,7 +80,21 @@ class Wget(FetchMethod):
             bb.utils.mkdirhier(os.path.dirname(dldir + os.sep + ud.localfile))
             fetchcmd += " -O " + dldir + os.sep + ud.localfile
 
-        uri = ud.url.split(";")[0]
+        # Process any ";;" in SRC_URI, these are escape sequences for ";" in URL
+        if ';;' in ud.url:
+           # If URL contains ';' the name of the downloaded file cannot be derived reliably
+           # (or derived at all) using URL string alone.
+           # Therefore we insist the file name is specified explicitly by the user.
+           if not 'downloadfilename' in ud.parm:
+               raise FetchError("Could not determine the name of the downloaded file. Please specify explicitly by using SRC_URI option 'downloadfilename'")
+
+           # Convert ";;" into something unique (not containing ';')
+           uri = ud.url.replace(";;","%3B%3B");
+           uri = uri.split(";")[0]
+           uri = uri.replace("%3B%3B",";");
+        else:
+           uri = ud.url.split(";")[0]
+
         if os.path.exists(ud.localpath):
             # file exists, but we didnt complete it.. trying again..
             fetchcmd += d.expand(" -c -P ${DL_DIR} '%s'" % uri)
Signature · 1 line
1.9.1
#1 lore raw
Quoted 19 lines · Juro Bystricky

Some URLs contain semi-colons. For example, some GIT repositories support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

This patch allows using of semi-colons in URLs: ';;' (double semi-colon) in SRC_URI is processed as a single semi-colon that is a part of a URL name.
For example, the above URL would become:

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47"

Note that it is not possible to determine the name of the downloaded file from URL alone. The onus to specify the proper name is on the user, via the parameter 'downloadfilename':

Quoted 6 lines

SRC_URI = "
http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=myfile.tar.gz
"

In my opinion, if we’re going to support this, we should really support it in a generic way, in urldecode/urlencode & the URL class, and if needed leverage that in wget.

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#2 lore raw

I agree that a generic solution is preferable. I also I think it is only prudent to support all valid URLs. The situation is complicated by the fact that at present it may not be possible to determine how to interpret the ‘;’ in SRC_URI. It can be part of the URL or it can be a SRC_URI delimiter/separator.
As I don’t suppose changing the delimiter character from semi-colon to something else (i.e. an unsafe URL character) is an option, some other changes to the SRC_URI syntax are needed, for example:

1. Some form of escape sequence (i.e. ‘;;’ means treat as ‘;’) in URL, i.e.

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=abc.tar"

2. Quoted string implementation, using one of the “unsafe” URL characters such as ‘`’, to delimit the URL

SRC_URI = "’ http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47`;downloadfilename=abc.tar"

3. Something else ?

Thanks

Juro

From: [email protected] [mailto:[email protected]] On Behalf Of Christopher Larson
Sent: Saturday, July 25, 2015 12:15 PM
To: Bystricky, Juro
Cc: [email protected]; Purdie, Richard
Subject: Re: [bitbake-devel] [PATCH] wget.py: support for semi-colons in URL

On Sat, Jul 25, 2015 at 11:32 AM, Juro Bystricky <[email protected]<mailto:[email protected]>> wrote:
Some URLs contain semi-colons. For example, some GIT repositories
support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

This patch allows using of semi-colons in URLs: ';;' (double semi-colon) in SRC_URI is processed as a single semi-colon that is a part of a URL name. For example, the above URL would become:

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47"

Note that it is not possible to determine the name of the downloaded file from URL alone. The onus to specify the proper name is on the user, via the parameter 'downloadfilename':

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=myfile.tar.gz"

In my opinion, if we’re going to support this, we should really support it in a generic way, in urldecode/urlencode & the URL class, and if needed leverage that in wget. --
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

#3 lore raw
Quoted 16 lines · Juro

I agree that a generic solution is preferable. I also I think it is only prudent to support all valid URLs.

The situation is complicated by the fact that at present it may not be possible to determine how to interpret the ‘;’ in SRC_URI.

It can be part of the URL or it can be a SRC_URI delimiter/separator.

As I don’t suppose changing the delimiter character from semi-colon to something else (i.e. an unsafe URL character)

is an option, some other changes to the SRC_URI syntax are needed, for example:

Quoted 7 lines

1. Some form of escape sequence (i.e. ‘;;’ means treat as ‘;’) in
URL, i.e.

SRC_URI = "
http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=abc.tar
"

This is probably the only sane bet to retain compatibility, at least as far as I can tell, but perhaps someone else has an idea.

2. Quoted string implementation, using one of the “unsafe” URL

Quoted 7 lines

characters such as ‘`’, to delimit the URL

SRC_URI = "’
http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47`;downloadfilename=abc.tar
<http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47;downloadfilename=abc.tar>
"

Clearly this would be ideal, and is what we should have done, but it’s a bit late now :) It’s not the only questionable choice we made in the URL handling back when we wrote the original fetcher (e.g. file:// rather than file:, but afaik one should only use the former if there’s a netloc/host).

Signature · 5 lines
Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics
#4 lore raw
Quoted 35 lines · Christopher Larson

On Mon, Jul 27, 2015 at 9:10 AM, Bystricky, Juro <[email protected]> wrote:
I agree that a generic solution is preferable. I also I think it is only prudent to support all valid URLs.

The situation is complicated by the fact that at present it may not be possible to determine how to interpret the ‘;’ in SRC_URI.

It can be part of the URL or it can be a SRC_URI delimiter/separator.

As I don’t suppose changing the delimiter character from semi-colon to something else (i.e. an unsafe URL character)

is an option, some other changes to the SRC_URI syntax are needed, for example:

1. Some form of escape sequence (i.e. ‘;;’ means treat as
‘;’) in URL, i.e.

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=abc.tar"

This is probably the only sane bet to retain compatibility, at least as far as I can tell, but perhaps someone else has an idea.

2. Quoted string implementation, using one of the
“unsafe” URL characters such as ‘`’, to delimit the URL

Quoted 8 lines

SRC_URI = "’
http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47`;downloadfilename=abc.tar"

Clearly this would be ideal, and is what we should have done, but it’s a bit late now :) It’s not the only questionable choice we made in the URL handling back when we wrote the original fetcher (e.g. file:// rather than file:, but afaik one should only use the former if there’s a netloc/host).

Yes, horse has bolted now. A bit like a lot of bitbake, hindsight is great! :}.

There is an alternative I've been mulling over the weekend:

http://abc123.com/git/?p=gcc/gcc.git;extraparams=;a=snapshot;h=a5dd47;downloadfilename=abc.tar"
or
http://abc123.com/git/?p=gcc/gcc.git;extraparams=a=snapshot%3Bh=a5dd47;downloadfilename=abc.tar"

(or some variant of that, pick your favourite quote characters and ; placement is for discussion). We'd then just pull out extraparams and unescape it somehow. Each fetcher could then deal with it as appropriate, or its just a wget fetcher specific option.

Just thinking out loud really...

Cheers,

Richard

#5 lore raw
In reply to Bystricky, Juro

I have not examined the code, but could the URL use the standard URL encoding mechanism to represent ; as %3B ?

The idea being that the initial "Bitbake URL" is parsed / split using the original string with semicolons and the URL escaped semicolon is passed through to a lower layer that uses that part of the string as an "Internet URL"

Cheers,
Peter

Quoted 83 lines · Juro

I agree that a generic solution is preferable. I also I think it is only prudent to support all valid URLs.

The situation is complicated by the fact that at present it may not be possible to determine how to interpret the ‘;’ in SRC_URI.

It can be part of the URL or it can be a SRC_URI delimiter/separator.

As I don’t suppose changing the delimiter character from semi-colon to something else (i.e. an unsafe URL character)

is an option, some other changes to the SRC_URI syntax are needed, for example:

1.Some form of escape sequence (i.e. ‘;;’ means treat as ‘;’) in URL, i.e.

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=abc.tar"

2.Quoted string implementation, using one of the “unsafe” URL characters such as ‘`’, to delimit the URL

SRC_URI = "’
http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47`;downloadfilename=abc.tar"

3.Something else ?

Thanks

Juro

*From:*[email protected] [mailto:[email protected]] *On Behalf Of *Christopher Larson
*Sent:* Saturday, July 25, 2015 12:15 PM
*To:* Bystricky, Juro
*Cc:* [email protected]; Purdie, Richard *Subject:* Re: [bitbake-devel] [PATCH] wget.py: support for semi-colons in URL

On Sat, Jul 25, 2015 at 11:32 AM, Juro Bystricky <[email protected] <mailto:[email protected]>> wrote:

Some URLs contain semi-colons. For example, some GIT repositories support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

This patch allows using of semi-colons in URLs: ';;' (double semi-colon) in SRC_URI is processed as a single semi-colon that is a part of a URL name.
For example, the above URL would become:

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47"

Note that it is not possible to determine the name of the downloaded file
from URL alone. The onus to specify the proper name is on the user, via the parameter 'downloadfilename':

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git;;a=snapshot;;h=a5dd47;downloadfilename=myfile.tar.gz"

<mailto:[email protected]>>

In my opinion, if we’re going to support this, we should really support it in a generic way, in urldecode/urlencode & the URL class, and if needed leverage that in wget.
--

Christopher Larson
clarson at kergoth dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Senior Software Engineer, Mentor Graphics

#6 lore raw

Excerpts from Peter Urbanec's message of 2015-07-28 07:47:17 +0200:

Quoted 7 lines

I have not examined the code, but could the URL use the standard URL encoding mechanism to represent ; as %3B ?

The idea being that the initial "Bitbake URL" is parsed / split using the original string with semicolons and the URL escaped semicolon is passed through to a lower layer that uses that part of the string as an "Internet URL"

URI encoded enitities today are handled correctly in my opinion. If I have a filename including a ;, I don't want it to be parsed as part of the URL, neither by bitbake nor the remote server --- that's where URI encoding comes in.

By hijacking URI encoding to mean "part of the URI, not parsed by bitbake", you will suprise users that expect it to mean "URI data, not URI control character" if I understand your proposal correctly.

That could be solved by double encoding, but I don't think that would be worth it, all occurences of URI encoding in SRC_URI today would have to be updated. E.g. %20 -> %2520.

Signature · 1 line
olof johansson
#7 lore raw
In reply to Juro Bystricky

Excerpts from Juro Bystricky's message of 2015-07-25 20:32:43 +0200:

Quoted 7 lines

Some URLs contain semi-colons. For example, some GIT repositories support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

W3C _recommends_ [1] that HTTP URL consumers treat ; in query strings as an &:

Quoted 3 lines

We recommend that HTTP server implementors, and in particular, CGI implementors support the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in this manner.

This means that

http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47

and

http://abc123.com/git/?p=gcc/gcc.git&a=snapshot&h=a5dd47

should be equivalent. I don't know how well spread this support is, or if it works in your case, but it's a workaround if it does at least.

1: http://www.w3.org/TR/1999/REC-html401-19991224/appendix/notes.html#h-B.2.2

Signature · 1 line
olof johansson
#8 lore raw

I tested your suggestion (replacing ";" with "&" in the SRC_URI ) and in my case it did work properly. So even if this may not solve everything, I believe this should be properly documented somewhere as this seems to be currently the only way to use SRC_URI with semi-colons in URL.

Note that one still needs to specify the downloaded file name manually, i.e.

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git&a=snapshot&h=a5dd47; downloadfilename=myfile.bz2"

Thanks

Juro Bystricky

Quoted 39 lines

-----Original Message-----
From: Olof Johansson [mailto:[email protected]]
Sent: Tuesday, July 28, 2015 4:01 AM
To: Bystricky, Juro; [email protected]
Subject: Re: [bitbake-devel] [PATCH] wget.py: support for semi-colons in URL

Excerpts from Juro Bystricky's message of 2015-07-25 20:32:43 +0200:

Quoted 7 lines

Some URLs contain semi-colons. For example, some GIT repositories support downloading snapshots using URL such as:

"http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47"

Currently there is no way to construct SRC_URI with such URLs. Bitbake uses semi-colons in SRC_URI as delimiters for various parameters.

W3C _recommends_ [1] that HTTP URL consumers treat ; in query strings as an &:

Quoted 3 lines

We recommend that HTTP server implementors, and in particular, CGI implementors support the use of ";" in place of "&" to save authors the trouble of escaping "&" characters in this manner.

This means that

http://abc123.com/git/?p=gcc/gcc.git;a=snapshot;h=a5dd47

and

http://abc123.com/git/?p=gcc/gcc.git&a=snapshot&h=a5dd47

should be equivalent. I don't know how well spread this support is, or if it works in your case, but it's a workaround if it does at least.

1: http://www.w3.org/TR/1999/REC-html401-
19991224/appendix/notes.html#h-B.2.2

--
olof johansson

#9 lore raw
Quoted 7 lines · Juro

I tested your suggestion (replacing ";" with "&" in the SRC_URI ) and in my case it did work properly. So even if this may not solve everything, I believe this should be properly documented somewhere as this seems to be currently the only way to use SRC_URI with semi-colons in URL.

Note that one still needs to specify the downloaded file name manually, i.e.

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git&a=snapshot&h=a5dd47; downloadfilename=myfile.bz2"

A patch adding some comments about this to wget.py would be nice, as would a patch documenting it in the bitbake manual...

Cheers,

Richard

#10 lore raw

OK, I will send in a new patch for bitbake manual.

Quoted 27 lines

-----Original Message-----
From: Richard Purdie [mailto:[email protected]]
Sent: Tuesday, July 28, 2015 12:38 PM
To: Bystricky, Juro
Cc: Olof Johansson; [email protected]
Subject: Re: [bitbake-devel] [PATCH] wget.py: support for semi-colons in URL

Quoted 1 line · Juro

I tested your suggestion (replacing ";" with "&" in the SRC_URI ) and in my

case it did work properly.

Quoted 2 lines

So even if this may not solve everything, I believe this should be properly documented somewhere as this seems to be currently the only

way to use SRC_URI with semi-colons in URL.

Quoted 2 lines

Note that one still needs to specify the downloaded file name manually,

i.e.

Quoted 2 lines

SRC_URI = "http://abc123.com/git/?p=gcc/gcc.git&a=snapshot&h=a5dd47;

downloadfilename=myfile.bz2"

A patch adding some comments about this to wget.py would be nice, as would a patch documenting it in the bitbake manual...

Cheers,

Richard