Skip to content

Commit

Permalink
Merge pull request #175 from sparkprime/zerostep
Browse files Browse the repository at this point in the history
Error rather than infinite loop when slice step == 0
  • Loading branch information
sparkprime committed May 10, 2016
2 parents 8d00178 + ed91720 commit bb0e032
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ limitations under the License.

slice(indexable, index, end, step)::
if (index != null && index < 0) || (end != null && end < 0) || (step != null && step < 0) then
error("got [%s:%s:%s] but negative index, end, and steps are not supported" % [index, end, step] )
error("got [%s:%s:%s] but negative index, end, and steps are not supported" % [index, end, step])
else if step == 0 then
error("got %s but step must be greater than 0" % step)
else if std.type(indexable) != "string" && std.type(indexable) != "array" then
error("std.slice accepts a string or an array, but got: %s" % std.type(indexable))
else
Expand Down

0 comments on commit bb0e032

Please sign in to comment.