Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(96)

Issue 4876046: code review 4876046: exp/template: don't panic on range of nil interface (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 8 months ago by niemeyer
Modified:
13 years, 8 months ago
Reviewers:
CC:
golang-dev, r, gustavo_niemeyer.net
Visibility:
Public.

Description

exp/template: don't panic on range of nil interface This avoids a non-obvious panic when range is used on a nil interface, and fixes it by behaving as if the range was empty. The new behavior is equivalent to the outcome of iterating on a nil map or slice, and is useful because it allows generic structures such as used in json (map[string]interface{}) to behave correctly if a key generally set to a list or map isn't present.

Patch Set 1 #

Patch Set 2 : code review 4876046: exp/template: don't panic on range of nil interface #

Patch Set 3 : diff -r 160518ccd695 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 160518ccd695 https://go.googlecode.com/hg/ #

Total comments: 8

Patch Set 5 : diff -r 160518ccd695 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 160518ccd695 https://go.googlecode.com/hg/ #

Patch Set 7 : diff -r af3bbd9ae031 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+4 lines, -1 line) Patch
M src/pkg/exp/template/exec.go View 1 2 3 4 1 chunk +3 lines, -1 line 0 comments Download
M src/pkg/exp/template/exec_test.go View 1 2 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 9
niemeyer
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 8 months ago (2011-08-14 00:11:01 UTC) #1
r
http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go File src/pkg/exp/template/exec.go (right): http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go#newcode237 src/pkg/exp/template/exec.go:237: break // Can't tell what the value might be ...
13 years, 8 months ago (2011-08-14 02:33:15 UTC) #2
niemeyer
Thanks for the review. Some follow ups: http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go File src/pkg/exp/template/exec.go (right): http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go#newcode239 src/pkg/exp/template/exec.go:239: s.errorf("range can't ...
13 years, 8 months ago (2011-08-14 03:13:15 UTC) #3
gustavo_niemeyer.net
> This will yield a different result. The goal as stated in the CL > ...
13 years, 8 months ago (2011-08-14 03:32:18 UTC) #4
r
http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go File src/pkg/exp/template/exec.go (right): http://codereview.appspot.com/4876046/diff/7001/src/pkg/exp/template/exec.go#newcode237 src/pkg/exp/template/exec.go:237: break // Can't tell what the value might be ...
13 years, 8 months ago (2011-08-14 08:09:26 UTC) #5
niemeyer
> drop this change, at least for now. it's separable and doesn't affect the > ...
13 years, 8 months ago (2011-08-14 19:31:50 UTC) #6
niemeyer
Hello golang-dev@googlegroups.com, r@golang.org, gustavo@niemeyer.net (cc: golang-dev@googlegroups.com), Please take another look.
13 years, 8 months ago (2011-08-14 19:32:17 UTC) #7
r
LGTM but update the CL description before submitting. it describes the reflect change no longer ...
13 years, 8 months ago (2011-08-15 00:52:56 UTC) #8
niemeyer
13 years, 8 months ago (2011-08-15 03:22:44 UTC) #9
*** Submitted as http://code.google.com/p/go/source/detail?r=db3b3cfd9d28 ***

exp/template: don't panic on range of nil interface

This avoids a non-obvious panic when range is used on a
nil interface, and fixes it by behaving as if the range
was empty.

The new behavior is equivalent to the outcome of iterating
on a nil map or slice, and is useful because it allows
generic structures such as used in json (map[string]interface{})
to behave correctly if a key generally set to a list or map
isn't present.

R=golang-dev, r, gustavo
CC=golang-dev
http://codereview.appspot.com/4876046
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b