Vendor dependencies for GCS
This commit is contained in:
parent
ba75a3884c
commit
8ca6a9a240
1228 changed files with 1769186 additions and 1 deletions
18
vendor/google.golang.org/api/googleapi/internal/uritemplates/LICENSE
generated
vendored
Normal file
18
vendor/google.golang.org/api/googleapi/internal/uritemplates/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
Copyright (c) 2013 Joshua Tacoma
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
248
vendor/google.golang.org/api/googleapi/internal/uritemplates/uritemplates.go
generated
vendored
Normal file
248
vendor/google.golang.org/api/googleapi/internal/uritemplates/uritemplates.go
generated
vendored
Normal file
|
@ -0,0 +1,248 @@
|
|||
// Copyright 2013 Joshua Tacoma. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Package uritemplates is a level 3 implementation of RFC 6570 (URI
|
||||
// Template, http://tools.ietf.org/html/rfc6570).
|
||||
// uritemplates does not support composite values (in Go: slices or maps)
|
||||
// and so does not qualify as a level 4 implementation.
|
||||
package uritemplates
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
unreserved = regexp.MustCompile("[^A-Za-z0-9\\-._~]")
|
||||
reserved = regexp.MustCompile("[^A-Za-z0-9\\-._~:/?#[\\]@!$&'()*+,;=]")
|
||||
validname = regexp.MustCompile("^([A-Za-z0-9_\\.]|%[0-9A-Fa-f][0-9A-Fa-f])+$")
|
||||
hex = []byte("0123456789ABCDEF")
|
||||
)
|
||||
|
||||
func pctEncode(src []byte) []byte {
|
||||
dst := make([]byte, len(src)*3)
|
||||
for i, b := range src {
|
||||
buf := dst[i*3 : i*3+3]
|
||||
buf[0] = 0x25
|
||||
buf[1] = hex[b/16]
|
||||
buf[2] = hex[b%16]
|
||||
}
|
||||
return dst
|
||||
}
|
||||
|
||||
// pairWriter is a convenience struct which allows escaped and unescaped
|
||||
// versions of the template to be written in parallel.
|
||||
type pairWriter struct {
|
||||
escaped, unescaped bytes.Buffer
|
||||
}
|
||||
|
||||
// Write writes the provided string directly without any escaping.
|
||||
func (w *pairWriter) Write(s string) {
|
||||
w.escaped.WriteString(s)
|
||||
w.unescaped.WriteString(s)
|
||||
}
|
||||
|
||||
// Escape writes the provided string, escaping the string for the
|
||||
// escaped output.
|
||||
func (w *pairWriter) Escape(s string, allowReserved bool) {
|
||||
w.unescaped.WriteString(s)
|
||||
if allowReserved {
|
||||
w.escaped.Write(reserved.ReplaceAllFunc([]byte(s), pctEncode))
|
||||
} else {
|
||||
w.escaped.Write(unreserved.ReplaceAllFunc([]byte(s), pctEncode))
|
||||
}
|
||||
}
|
||||
|
||||
// Escaped returns the escaped string.
|
||||
func (w *pairWriter) Escaped() string {
|
||||
return w.escaped.String()
|
||||
}
|
||||
|
||||
// Unescaped returns the unescaped string.
|
||||
func (w *pairWriter) Unescaped() string {
|
||||
return w.unescaped.String()
|
||||
}
|
||||
|
||||
// A uriTemplate is a parsed representation of a URI template.
|
||||
type uriTemplate struct {
|
||||
raw string
|
||||
parts []templatePart
|
||||
}
|
||||
|
||||
// parse parses a URI template string into a uriTemplate object.
|
||||
func parse(rawTemplate string) (*uriTemplate, error) {
|
||||
split := strings.Split(rawTemplate, "{")
|
||||
parts := make([]templatePart, len(split)*2-1)
|
||||
for i, s := range split {
|
||||
if i == 0 {
|
||||
if strings.Contains(s, "}") {
|
||||
return nil, errors.New("unexpected }")
|
||||
}
|
||||
parts[i].raw = s
|
||||
continue
|
||||
}
|
||||
subsplit := strings.Split(s, "}")
|
||||
if len(subsplit) != 2 {
|
||||
return nil, errors.New("malformed template")
|
||||
}
|
||||
expression := subsplit[0]
|
||||
var err error
|
||||
parts[i*2-1], err = parseExpression(expression)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
parts[i*2].raw = subsplit[1]
|
||||
}
|
||||
return &uriTemplate{
|
||||
raw: rawTemplate,
|
||||
parts: parts,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type templatePart struct {
|
||||
raw string
|
||||
terms []templateTerm
|
||||
first string
|
||||
sep string
|
||||
named bool
|
||||
ifemp string
|
||||
allowReserved bool
|
||||
}
|
||||
|
||||
type templateTerm struct {
|
||||
name string
|
||||
explode bool
|
||||
truncate int
|
||||
}
|
||||
|
||||
func parseExpression(expression string) (result templatePart, err error) {
|
||||
switch expression[0] {
|
||||
case '+':
|
||||
result.sep = ","
|
||||
result.allowReserved = true
|
||||
expression = expression[1:]
|
||||
case '.':
|
||||
result.first = "."
|
||||
result.sep = "."
|
||||
expression = expression[1:]
|
||||
case '/':
|
||||
result.first = "/"
|
||||
result.sep = "/"
|
||||
expression = expression[1:]
|
||||
case ';':
|
||||
result.first = ";"
|
||||
result.sep = ";"
|
||||
result.named = true
|
||||
expression = expression[1:]
|
||||
case '?':
|
||||
result.first = "?"
|
||||
result.sep = "&"
|
||||
result.named = true
|
||||
result.ifemp = "="
|
||||
expression = expression[1:]
|
||||
case '&':
|
||||
result.first = "&"
|
||||
result.sep = "&"
|
||||
result.named = true
|
||||
result.ifemp = "="
|
||||
expression = expression[1:]
|
||||
case '#':
|
||||
result.first = "#"
|
||||
result.sep = ","
|
||||
result.allowReserved = true
|
||||
expression = expression[1:]
|
||||
default:
|
||||
result.sep = ","
|
||||
}
|
||||
rawterms := strings.Split(expression, ",")
|
||||
result.terms = make([]templateTerm, len(rawterms))
|
||||
for i, raw := range rawterms {
|
||||
result.terms[i], err = parseTerm(raw)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func parseTerm(term string) (result templateTerm, err error) {
|
||||
// TODO(djd): Remove "*" suffix parsing once we check that no APIs have
|
||||
// mistakenly used that attribute.
|
||||
if strings.HasSuffix(term, "*") {
|
||||
result.explode = true
|
||||
term = term[:len(term)-1]
|
||||
}
|
||||
split := strings.Split(term, ":")
|
||||
if len(split) == 1 {
|
||||
result.name = term
|
||||
} else if len(split) == 2 {
|
||||
result.name = split[0]
|
||||
var parsed int64
|
||||
parsed, err = strconv.ParseInt(split[1], 10, 0)
|
||||
result.truncate = int(parsed)
|
||||
} else {
|
||||
err = errors.New("multiple colons in same term")
|
||||
}
|
||||
if !validname.MatchString(result.name) {
|
||||
err = errors.New("not a valid name: " + result.name)
|
||||
}
|
||||
if result.explode && result.truncate > 0 {
|
||||
err = errors.New("both explode and prefix modifers on same term")
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
// Expand expands a URI template with a set of values to produce the
|
||||
// resultant URI. Two forms of the result are returned: one with all the
|
||||
// elements escaped, and one with the elements unescaped.
|
||||
func (t *uriTemplate) Expand(values map[string]string) (escaped, unescaped string) {
|
||||
var w pairWriter
|
||||
for _, p := range t.parts {
|
||||
p.expand(&w, values)
|
||||
}
|
||||
return w.Escaped(), w.Unescaped()
|
||||
}
|
||||
|
||||
func (tp *templatePart) expand(w *pairWriter, values map[string]string) {
|
||||
if len(tp.raw) > 0 {
|
||||
w.Write(tp.raw)
|
||||
return
|
||||
}
|
||||
var first = true
|
||||
for _, term := range tp.terms {
|
||||
value, exists := values[term.name]
|
||||
if !exists {
|
||||
continue
|
||||
}
|
||||
if first {
|
||||
w.Write(tp.first)
|
||||
first = false
|
||||
} else {
|
||||
w.Write(tp.sep)
|
||||
}
|
||||
tp.expandString(w, term, value)
|
||||
}
|
||||
}
|
||||
|
||||
func (tp *templatePart) expandName(w *pairWriter, name string, empty bool) {
|
||||
if tp.named {
|
||||
w.Write(name)
|
||||
if empty {
|
||||
w.Write(tp.ifemp)
|
||||
} else {
|
||||
w.Write("=")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (tp *templatePart) expandString(w *pairWriter, t templateTerm, s string) {
|
||||
if len(s) > t.truncate && t.truncate > 0 {
|
||||
s = s[:t.truncate]
|
||||
}
|
||||
tp.expandName(w, t.name, len(s) == 0)
|
||||
w.Escape(s, tp.allowReserved)
|
||||
}
|
280
vendor/google.golang.org/api/googleapi/internal/uritemplates/uritemplates_test.go
generated
vendored
Normal file
280
vendor/google.golang.org/api/googleapi/internal/uritemplates/uritemplates_test.go
generated
vendored
Normal file
|
@ -0,0 +1,280 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package uritemplates
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/url"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func ExampleExpand() {
|
||||
values := map[string]string{
|
||||
"user": "golang",
|
||||
"repo": "go",
|
||||
}
|
||||
expanded, _, err := Expand("https://api.github.com/repos{/user,repo}", values)
|
||||
if err != nil {
|
||||
log.Fatalf("Error expanding template: %v", err)
|
||||
}
|
||||
fmt.Println(expanded)
|
||||
// Output:
|
||||
// https://api.github.com/repos/golang/go
|
||||
}
|
||||
|
||||
func TestExpand(t *testing.T) {
|
||||
testCases := []struct {
|
||||
tmpl string
|
||||
values map[string]string
|
||||
want string
|
||||
}{
|
||||
// These examples come from the RFC:
|
||||
// http://tools.ietf.org/html/rfc6570
|
||||
{
|
||||
tmpl: "http://www.example.com/foo{?query,number}",
|
||||
values: map[string]string{"query": "mycelium", "number": "100"},
|
||||
want: "http://www.example.com/foo?query=mycelium&number=100",
|
||||
},
|
||||
{
|
||||
tmpl: "http://www.example.com/foo{?query,number}",
|
||||
values: map[string]string{"query": "mycelium"},
|
||||
want: "http://www.example.com/foo?query=mycelium",
|
||||
},
|
||||
{
|
||||
tmpl: "http://www.example.com/foo{?query,number}",
|
||||
values: map[string]string{},
|
||||
want: "http://www.example.com/foo",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range testCases {
|
||||
exp, _, err := Expand(tt.tmpl, tt.values)
|
||||
if err != nil {
|
||||
t.Errorf("Expand(%q, %v) error: %v", tt.tmpl, tt.values, err)
|
||||
continue
|
||||
}
|
||||
if exp != tt.want {
|
||||
t.Errorf("Expand(%q, %v)\ngot %q\nwant %q", tt.tmpl, tt.values, exp, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandRFCLevels(t *testing.T) {
|
||||
values := map[string]string{
|
||||
"dub": "me/too",
|
||||
"hello": "Hello World!",
|
||||
"half": "50%",
|
||||
"var": "value",
|
||||
"who": "fred",
|
||||
"base": "http://example.com/home/",
|
||||
"path": "/foo/bar",
|
||||
"semi": ";",
|
||||
"v": "6",
|
||||
"x": "1024",
|
||||
"y": "768",
|
||||
"empty": "",
|
||||
// undef not mapped.
|
||||
}
|
||||
testCases := []struct {
|
||||
tmpl, want string
|
||||
}{
|
||||
// These examples come from the RFC levels specification.
|
||||
// http://tools.ietf.org/html/rfc6570
|
||||
// Level 1 examples.
|
||||
{tmpl: "{var}", want: "value"},
|
||||
{tmpl: "{hello}", want: "Hello%20World%21"},
|
||||
|
||||
// Level 2 examples.
|
||||
{tmpl: "{+var}", want: "value"},
|
||||
{tmpl: "{+hello}", want: "Hello%20World!"},
|
||||
{tmpl: "{+path}/here", want: "/foo/bar/here"},
|
||||
{tmpl: "here?ref={+path}", want: "here?ref=/foo/bar"},
|
||||
{tmpl: "X{#var}", want: "X#value"},
|
||||
{tmpl: "X{#hello}", want: "X#Hello%20World!"},
|
||||
|
||||
// Level 3 examples.
|
||||
{tmpl: "map?{x,y}", want: "map?1024,768"},
|
||||
{tmpl: "{x,hello,y}", want: "1024,Hello%20World%21,768"},
|
||||
{tmpl: "{+x,hello,y}", want: "1024,Hello%20World!,768"},
|
||||
{tmpl: "{+path,x}/here", want: "/foo/bar,1024/here"},
|
||||
{tmpl: "{#x,hello,y}", want: "#1024,Hello%20World!,768"},
|
||||
{tmpl: "{#path,x}/here", want: "#/foo/bar,1024/here"},
|
||||
{tmpl: "X{.var}", want: "X.value"},
|
||||
{tmpl: "X{.x,y}", want: "X.1024.768"},
|
||||
{tmpl: "{/var}", want: "/value"},
|
||||
{tmpl: "{/var,x}/here", want: "/value/1024/here"},
|
||||
{tmpl: "{;x,y}", want: ";x=1024;y=768"},
|
||||
{tmpl: "{;x,y,empty}", want: ";x=1024;y=768;empty"},
|
||||
{tmpl: "{?x,y}", want: "?x=1024&y=768"},
|
||||
{tmpl: "{?x,y,empty}", want: "?x=1024&y=768&empty="},
|
||||
{tmpl: "?fixed=yes{&x}", want: "?fixed=yes&x=1024"},
|
||||
{tmpl: "{&x,y,empty}", want: "&x=1024&y=768&empty="},
|
||||
|
||||
{tmpl: "{var:3}", want: "val"},
|
||||
{tmpl: "{var:30}", want: "value"},
|
||||
{tmpl: "{+path:6}/here", want: "/foo/b/here"},
|
||||
{tmpl: "{#path:6}/here", want: "#/foo/b/here"},
|
||||
{tmpl: "X{.var:3}", want: "X.val"},
|
||||
{tmpl: "{/var:1,var}", want: "/v/value"},
|
||||
{tmpl: "{;hello:5}", want: ";hello=Hello"},
|
||||
{tmpl: "{?var:3}", want: "?var=val"},
|
||||
{tmpl: "{&var:3}", want: "&var=val"},
|
||||
|
||||
// 2.4.1 Prefix values.
|
||||
{tmpl: "{var}", want: "value"},
|
||||
{tmpl: "{var:20}", want: "value"},
|
||||
{tmpl: "{var:3}", want: "val"},
|
||||
{tmpl: "{semi}", want: "%3B"},
|
||||
{tmpl: "{semi:2}", want: "%3B"},
|
||||
// 3.2.2. Simple String Expansion: {var}
|
||||
{tmpl: "{var}", want: "value"},
|
||||
{tmpl: "{hello}", want: "Hello%20World%21"},
|
||||
{tmpl: "{half}", want: "50%25"},
|
||||
{tmpl: "O{empty}X", want: "OX"},
|
||||
{tmpl: "O{undef}X", want: "OX"},
|
||||
{tmpl: "{x,y}", want: "1024,768"},
|
||||
{tmpl: "{x,hello,y}", want: "1024,Hello%20World%21,768"},
|
||||
{tmpl: "?{x,empty}", want: "?1024,"},
|
||||
{tmpl: "?{x,undef}", want: "?1024"},
|
||||
{tmpl: "?{undef,y}", want: "?768"},
|
||||
{tmpl: "{var:3}", want: "val"},
|
||||
{tmpl: "{var:30}", want: "value"},
|
||||
// 3.2.3. Reserved Expansion: {+var}
|
||||
{tmpl: "{+var}", want: "value"},
|
||||
{tmpl: "{+hello}", want: "Hello%20World!"},
|
||||
{tmpl: "{+half}", want: "50%25"},
|
||||
{tmpl: "{base}index", want: "http%3A%2F%2Fexample.com%2Fhome%2Findex"},
|
||||
{tmpl: "{+base}index", want: "http://example.com/home/index"},
|
||||
{tmpl: "O{+empty}X", want: "OX"},
|
||||
{tmpl: "O{+undef}X", want: "OX"},
|
||||
{tmpl: "{+path}/here", want: "/foo/bar/here"},
|
||||
{tmpl: "here?ref={+path}", want: "here?ref=/foo/bar"},
|
||||
{tmpl: "up{+path}{var}/here", want: "up/foo/barvalue/here"},
|
||||
{tmpl: "{+x,hello,y}", want: "1024,Hello%20World!,768"},
|
||||
{tmpl: "{+path,x}/here", want: "/foo/bar,1024/here"},
|
||||
{tmpl: "{+path:6}/here", want: "/foo/b/here"},
|
||||
// 3.2.4. Fragment Expansion: {#var}
|
||||
{tmpl: "{#var}", want: "#value"},
|
||||
{tmpl: "{#hello}", want: "#Hello%20World!"},
|
||||
{tmpl: "{#half}", want: "#50%25"},
|
||||
{tmpl: "foo{#empty}", want: "foo#"},
|
||||
{tmpl: "foo{#undef}", want: "foo"},
|
||||
{tmpl: "{#x,hello,y}", want: "#1024,Hello%20World!,768"},
|
||||
{tmpl: "{#path,x}/here", want: "#/foo/bar,1024/here"},
|
||||
{tmpl: "{#path:6}/here", want: "#/foo/b/here"},
|
||||
// 3.2.5. Label Expansion with Dot-Prefix: {.var}
|
||||
{tmpl: "{.who}", want: ".fred"},
|
||||
{tmpl: "{.who,who}", want: ".fred.fred"},
|
||||
{tmpl: "{.half,who}", want: ".50%25.fred"},
|
||||
{tmpl: "X{.var}", want: "X.value"},
|
||||
{tmpl: "X{.empty}", want: "X."},
|
||||
{tmpl: "X{.undef}", want: "X"},
|
||||
{tmpl: "X{.var:3}", want: "X.val"},
|
||||
// 3.2.6. Path Segment Expansion: {/var}
|
||||
{tmpl: "{/who}", want: "/fred"},
|
||||
{tmpl: "{/who,who}", want: "/fred/fred"},
|
||||
{tmpl: "{/half,who}", want: "/50%25/fred"},
|
||||
{tmpl: "{/who,dub}", want: "/fred/me%2Ftoo"},
|
||||
{tmpl: "{/var}", want: "/value"},
|
||||
{tmpl: "{/var,empty}", want: "/value/"},
|
||||
{tmpl: "{/var,undef}", want: "/value"},
|
||||
{tmpl: "{/var,x}/here", want: "/value/1024/here"},
|
||||
{tmpl: "{/var:1,var}", want: "/v/value"},
|
||||
// 3.2.7. Path-Style Parameter Expansion: {;var}
|
||||
{tmpl: "{;who}", want: ";who=fred"},
|
||||
{tmpl: "{;half}", want: ";half=50%25"},
|
||||
{tmpl: "{;empty}", want: ";empty"},
|
||||
{tmpl: "{;v,empty,who}", want: ";v=6;empty;who=fred"},
|
||||
{tmpl: "{;v,bar,who}", want: ";v=6;who=fred"},
|
||||
{tmpl: "{;x,y}", want: ";x=1024;y=768"},
|
||||
{tmpl: "{;x,y,empty}", want: ";x=1024;y=768;empty"},
|
||||
{tmpl: "{;x,y,undef}", want: ";x=1024;y=768"},
|
||||
{tmpl: "{;hello:5}", want: ";hello=Hello"},
|
||||
// 3.2.8. Form-Style Query Expansion: {?var}
|
||||
{tmpl: "{?who}", want: "?who=fred"},
|
||||
{tmpl: "{?half}", want: "?half=50%25"},
|
||||
{tmpl: "{?x,y}", want: "?x=1024&y=768"},
|
||||
{tmpl: "{?x,y,empty}", want: "?x=1024&y=768&empty="},
|
||||
{tmpl: "{?x,y,undef}", want: "?x=1024&y=768"},
|
||||
{tmpl: "{?var:3}", want: "?var=val"},
|
||||
// 3.2.9. Form-Style Query Continuation: {&var}
|
||||
{tmpl: "{&who}", want: "&who=fred"},
|
||||
{tmpl: "{&half}", want: "&half=50%25"},
|
||||
{tmpl: "?fixed=yes{&x}", want: "?fixed=yes&x=1024"},
|
||||
{tmpl: "{&x,y,empty}", want: "&x=1024&y=768&empty="},
|
||||
{tmpl: "{&x,y,undef}", want: "&x=1024&y=768"},
|
||||
{tmpl: "{&var:3}", want: "&var=val"},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
esc, unesc, err := Expand(tt.tmpl, values)
|
||||
if err != nil {
|
||||
t.Errorf("Expand(%q) error: %v", tt.tmpl, err)
|
||||
continue
|
||||
}
|
||||
if esc != tt.want {
|
||||
t.Errorf("Expand(%q)\ngot %q\nwant %q", tt.tmpl, esc, tt.want)
|
||||
}
|
||||
// Check that the escaped form is equivalent to unescaped.
|
||||
urlUnesc, err := url.QueryUnescape(esc)
|
||||
if err != nil {
|
||||
t.Errorf("Expand(%q) gave invalid escaping %q: %v", tt.tmpl, esc, err)
|
||||
continue
|
||||
}
|
||||
if urlUnesc != unesc {
|
||||
t.Errorf("Expand(%q) gave inconsistent escaped/unescaped\nunescaped %q\nescaped %q\nwhich is %q", tt.tmpl, unesc, esc, urlUnesc)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExpandUnescaped(t *testing.T) {
|
||||
testCases := []struct {
|
||||
tmpl, wantEsc, wantUnesc string
|
||||
values map[string]string
|
||||
}{
|
||||
{
|
||||
tmpl: "/foo/{bucket}/bar",
|
||||
values: map[string]string{
|
||||
"bucket": "simple",
|
||||
},
|
||||
wantEsc: "/foo/simple/bar",
|
||||
wantUnesc: "/foo/simple/bar",
|
||||
},
|
||||
{
|
||||
tmpl: "/foo/{bucket}/bar",
|
||||
values: map[string]string{
|
||||
"bucket": "path/with/slash",
|
||||
},
|
||||
wantEsc: "/foo/path%2Fwith%2Fslash/bar",
|
||||
wantUnesc: "/foo/path/with/slash/bar",
|
||||
},
|
||||
{
|
||||
tmpl: "/foo/{+bucket}/bar",
|
||||
values: map[string]string{
|
||||
"bucket": "path/with/slash",
|
||||
},
|
||||
wantEsc: "/foo/path/with/slash/bar",
|
||||
wantUnesc: "/foo/path/with/slash/bar",
|
||||
},
|
||||
{
|
||||
tmpl: "/foo/{bucket}/bar",
|
||||
values: map[string]string{
|
||||
"bucket": "double%2Fescaped",
|
||||
},
|
||||
wantEsc: "/foo/double%252Fescaped/bar",
|
||||
wantUnesc: "/foo/double%2Fescaped/bar",
|
||||
},
|
||||
}
|
||||
for _, tt := range testCases {
|
||||
esc, unesc, err := Expand(tt.tmpl, tt.values)
|
||||
if err != nil {
|
||||
t.Errorf("Expand(%q) error: %v", tt.tmpl, err)
|
||||
continue
|
||||
}
|
||||
if esc != tt.wantEsc || unesc != tt.wantUnesc {
|
||||
t.Errorf("Expand(%q)\ngot esc=%q, unesc=%q\nwant esc=%q, unesc=%q", tt.tmpl, esc, unesc, tt.wantEsc, tt.wantUnesc)
|
||||
}
|
||||
}
|
||||
}
|
17
vendor/google.golang.org/api/googleapi/internal/uritemplates/utils.go
generated
vendored
Normal file
17
vendor/google.golang.org/api/googleapi/internal/uritemplates/utils.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
// Copyright 2016 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package uritemplates
|
||||
|
||||
// Expand parses then expands a URI template with a set of values to produce
|
||||
// the resultant URI. Two forms of the result are returned: one with all the
|
||||
// elements escaped, and one with the elements unescaped.
|
||||
func Expand(path string, values map[string]string) (escaped, unescaped string, err error) {
|
||||
template, err := parse(path)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
escaped, unescaped = template.Expand(values)
|
||||
return escaped, unescaped, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue