diff options
author | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
---|---|---|
committer | Nathan Dench <ndenc2@gmail.com> | 2019-05-24 15:16:44 +1000 |
commit | 107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch) | |
tree | ca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl | |
parent | 844b5a68d8af4791755b8f0ad293cc99f5959183 (diff) | |
download | terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip |
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl')
-rw-r--r-- | vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl index 85d43bb..3c642d9 100644 --- a/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl +++ b/vendor/github.com/zclconf/go-cty/cty/function/stdlib/format_fsm.rl | |||
@@ -12,6 +12,7 @@ import ( | |||
12 | "unicode/utf8" | 12 | "unicode/utf8" |
13 | 13 | ||
14 | "github.com/zclconf/go-cty/cty" | 14 | "github.com/zclconf/go-cty/cty" |
15 | "github.com/zclconf/go-cty/cty/function" | ||
15 | ) | 16 | ) |
16 | 17 | ||
17 | %%{ | 18 | %%{ |
@@ -23,6 +24,7 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
23 | data := format | 24 | data := format |
24 | nextArg := 1 // arg numbers are 1-based | 25 | nextArg := 1 // arg numbers are 1-based |
25 | var verb formatVerb | 26 | var verb formatVerb |
27 | highestArgIdx := 0 // zero means "none", since arg numbers are 1-based | ||
26 | 28 | ||
27 | %%{ | 29 | %%{ |
28 | 30 | ||
@@ -102,6 +104,10 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
102 | verb.Raw = data[ts:te] | 104 | verb.Raw = data[ts:te] |
103 | verb.Offset = ts | 105 | verb.Offset = ts |
104 | 106 | ||
107 | if verb.ArgNum > highestArgIdx { | ||
108 | highestArgIdx = verb.ArgNum | ||
109 | } | ||
110 | |||
105 | err := formatAppend(&verb, &buf, a) | 111 | err := formatAppend(&verb, &buf, a) |
106 | if err != nil { | 112 | if err != nil { |
107 | return buf.String(), err | 113 | return buf.String(), err |
@@ -175,7 +181,17 @@ func formatFSM(format string, a []cty.Value) (string, error) { | |||
175 | // be impossible (the scanner matches all bytes _somehow_) but we'll | 181 | // be impossible (the scanner matches all bytes _somehow_) but we'll |
176 | // flag it anyway rather than just losing data from the end. | 182 | // flag it anyway rather than just losing data from the end. |
177 | if cs < formatfsm_first_final { | 183 | if cs < formatfsm_first_final { |
178 | return buf.String(), fmt.Errorf("extraneous characters beginning at offset %i", p) | 184 | return buf.String(), fmt.Errorf("extraneous characters beginning at offset %d", p) |
185 | } | ||
186 | |||
187 | if highestArgIdx < len(a) { | ||
188 | // Extraneous args are an error, to more easily detect mistakes | ||
189 | firstBad := highestArgIdx+1 | ||
190 | if highestArgIdx == 0 { | ||
191 | // Custom error message for this case | ||
192 | return buf.String(), function.NewArgErrorf(firstBad, "too many arguments; no verbs in format string") | ||
193 | } | ||
194 | return buf.String(), function.NewArgErrorf(firstBad, "too many arguments; only %d used by format string", highestArgIdx) | ||
179 | } | 195 | } |
180 | 196 | ||
181 | return buf.String(), nil | 197 | return buf.String(), nil |