Unidata / thredds

THREDDS Data Server v4.6
https://www.unidata.ucar.edu/software/tds/v4.6/index.html
265 stars 179 forks source link

double encoding of spaces in filenames when user click on "Get Binary" or "Get ASCII" in OPeNDAP download form #1363

Closed Alexander-Barth closed 3 years ago

Alexander-Barth commented 3 years ago

A user notified me that the "Get Binary" or "Get ASCII" buttons in the OPeNDAP download form do not work if the filename contains a space. As a example, I have placed two files "example_1.nc" and "example 1.nc" on a test server:

http://opendap2.oceanbrowser.net/thredds/dodsC/data/example_1.nc.html http://opendap2.oceanbrowser.net/thredds/dodsC/data/example%201.nc.html

(those links are also available from http://opendap2.oceanbrowser.net/thredds/catalog/data/catalog.html)

The "Get ASCII" button works for the first URL, but not for the 2nd where I get the error message:

Error {
    code = 404;
    message = "data/example%201.nc";
};

In the server log, I see this error:

172.17.0.1 - - [15/Jun/2021:14:55:08 +0000] "GET /thredds/dodsC/data/example%25201.nc.ascii? HTTP/1.1" 404 75

However, when I manual replace the "Data URL" in the download form by http://opendap2.oceanbrowser.net/thredds/dodsC/data/example 1.nc (which defaults to http://opendap2.oceanbrowser.net/thredds/dodsC/data/example%201.nc), the Get Ascii button works.

I am using the current docker image unidata/thredds-docker which includes Thredds 4.6.16.1:

$ docker inspect unidata/thredds-docker | grep Created
        "Created": "2021-05-26T00:51:37.068486187Z",
$ docker inspect unidata/thredds-docker | grep TDS
                "TDS_VERSION=4.6.16.1",
[...]

Any advice would be greatly appreciated. Are there some option that need to be set to avoid this URL encoding issue? Thanks a lot for your help!

meliezer commented 3 years ago

It also happens for spaces in the path. For some reason the GET includes %2520 instead of %20 for spaces.

lesserwhirls commented 3 years ago

There is some javascript used in the OPeNDAP html data access page that makes a web request when you click "Get Binary" or "Get ASCII", and that code makes sure to encode the URL before making those requests. It currently encodes the entire URL, but it looks like it should only encode the query portion of the URL. What happens is the percent sign in the encoded space gets encoded a second time (to %25) on submission. It should be a relatively simple fix though. Thanks for the report!

Alexander-Barth commented 3 years ago

Thanks for your feedback! I think that this is indeed the issue.

The javascript code in the HTML page:

function ascii_button() {
    var url = new String(document.forms[0].url.value);

    var url_parts = url.split("?");
    /* handle case where constraint is null. */
    if (url_parts[1] != null) {
        var ascii_url = url_parts[0] + ".ascii?" + url_parts[1];
    }
    else {
        var ascii_url = url_parts[0] + ".ascii?";
    }

    window.open(encodeURI(ascii_url), "ASCII_Data");
}

I guess that only url_parts[1] should be encoded (as you mentioned). In the download form, Action, Data URL, Global Attributes, Variables are (currently) broken links to like links these:

https://www.opendap.org/online_help_files/opendap_form_help.html#data_url

I was wondering if you were aware of this.

Thanks again for your help!

lesserwhirls commented 3 years ago

Both of these issues (encoding and links to docs) should be fixed in 4.6.x and 5.0 now. Thank you again for your report!

Alexander-Barth commented 3 years ago

This is great! Do you have already an idea when will be a release with this fix? Thanks a lot!