Skip to content

Commit

Permalink
URL encode GCS file names
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
chrisst authored and modular-magician committed Apr 4, 2019
1 parent 324e880 commit 763e210
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions google-beta/data_source_google_storage_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package google

import (
"fmt"
"net/url"
"strings"

"github.com/hashicorp/terraform/helper/schema"
)
Expand All @@ -24,6 +26,12 @@ func dataSourceGoogleStorageBucketObjectRead(d *schema.ResourceData, meta interf
bucket := d.Get("bucket").(string)
name := d.Get("name").(string)

// URL encode folder names, but to ensure backward compatibility don't url encode
// them if they were already encoded manually in config.
// see https://github.com/terraform-providers/terraform-provider-google/issues/3176
if strings.Contains(name, "/") {
name = url.QueryEscape(name)
}
// Using REST apis because the storage go client doesn't support folders
url := fmt.Sprintf("https://www.googleapis.com/storage/v1/b/%s/o/%s", bucket, name)

Expand Down

0 comments on commit 763e210

Please sign in to comment.