Skip to content

Broken StoragePath.Normalize, leading to broken Azure SAS URLs when using Azurite #94

Description

@vvuk

Azure SAS URLs are created here in AzureBlobStorage using:

			if (includeUrl) {
				string url = new Uri(_client.Uri, StoragePath.Normalize(fullPath)).ToString();
				url += "?";
				url += sas;
				return url;
			}

Typically, the _client.Uri will be something like https://myaccount.blob.core.windows.net/ or similar. However, when using Azurite, it's something like http://127.0.0.1:51256/devstoreaccount1/, with the devstoreaccount1 part being important.

In the function above, the fullPath should be something like container/name. However, StoragePath.Normalize is returning /container/name, and I don't understand why. This code here is doing it, removeTrailingSlash is false here:

			return removeTrailingSlash
			   ? path
			   : PathSeparatorString + path;

This makes no sense -- if "remove trailing slash" is false, the method.. prepends a slash? Also, given how this method is implemented, it's impossible for there to ever be a leading or trailing slash here. It splits the path by the separator with RemoveEmptyEntries and then recombines it.

All of this leads to the Uri() constructor stripping devstoreaccount1 from the base Uri. There's an additional subtle bug here -- connection strings for Azurite include a BlobEndpoint=http://127.0.0.1:51256/devstoreaccount1 (note lack of trailing slash). This works until a Uri constructor is used like the above -- Uri will strip off the last base path element if it doesn't end in a /.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions