1
0
mirror of https://github.com/golang/go synced 2024-10-04 10:21:21 -06:00
Commit Graph

306 Commits

Author SHA1 Message Date
Brad Fitzpatrick
d8e27db395 undo CL 12486043 / ab644299d124
Uglier.

««« original CL description
all: use strings.IndexByte instead of Index where possible

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12486043
»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/12485044
2013-08-05 16:27:24 -07:00
Brad Fitzpatrick
4c772cda54 all: use strings.IndexByte instead of Index where possible
R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/12486043
2013-08-05 15:46:06 -07:00
Rob Pike
16c9d3616a various: deleted unused items
R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/12396043
2013-08-03 16:01:04 +10:00
Alex A Skinner
789e1c351e encoding/xml: Do not pass through invalid utf8 bytes
EscapeText now escapes 0xFFFD returned from DecodeRune as 0xFFFD, rather than passing through the original byte.
Fixes #5880.

R=golang-dev, r, bradfitz, adg
CC=golang-dev
https://golang.org/cl/11975043
2013-07-30 14:11:47 +10:00
Rob Pike
abe384f68a all: be more idiomatic when documenting boolean return values.
Phrases like "returns whether or not the image is opaque" could be
describing what the function does (it always returns, regardless of
the opacity) or what it returns (a boolean indicating the opacity).
Even when the "or not" is missing, the phrasing is bizarre.

Go with "reports whether", which is still clunky but at least makes
it clear we're talking about the return value.

These were edited by hand. A few were cleaned up in other ways.

R=golang-dev, dsymonds
CC=golang-dev
https://golang.org/cl/11699043
2013-07-23 11:59:49 +10:00
Brad Fitzpatrick
48b9be2b19 all: change "true iff" to "whether" in public docs
For consistency with Go documentation style.

R=golang-dev, khr
CC=golang-dev
https://golang.org/cl/11697043
2013-07-22 16:20:30 -07:00
Russ Cox
4274d074dc encoding/json: add more tests for UTF-8 coercion
Suggested by Rob in CL 11211045, but the mail arrived
moments after hg submit completed.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/11138045
2013-07-12 20:40:50 -04:00
Russ Cox
4419d7e53c undo CL 11161044 / ba455262a9db
I want to think more carefully about this.

We put this in because Marshal encoded named []byte but Unmarshal rejected them.
And we noticed that Marshal's behavior was undocumented so we documented it.
But I am starting to think the docs and Unmarshal were correct and Marshal's
behavior was the problem.

Rolling back to give us more time to think.

««« original CL description
json: unmarshal types that are byte slices.

The json package cheerfully would marshal

        type S struct {
                IP net.IP
        }

but would give an error when unmarshalling.  This change allows any
type whose concrete type is a byte slice to be unmarshalled from a
string.

Fixes #5086.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11161044

»»»

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/11042046
2013-07-12 17:42:01 -04:00
Russ Cox
64054a40ad encoding/json: coerce invalid UTF-8 to valid UTF-8 during Marshal
In practice, rejecting an entire structure due to a single invalid byte
in a string is just too picky, and too hard to track down.
Be consistent with the bulk of the standard library by converting
invalid UTF-8 into UTF-8 with replacement runes.

R=golang-dev, crawshaw
CC=golang-dev
https://golang.org/cl/11211045
2013-07-12 17:37:10 -04:00
David Symonds
d754647963 encoding/json: escape U+2028 and U+2029.
Fixes #5836.

R=golang-dev, bradfitz, r, rsc
CC=golang-dev
https://golang.org/cl/10883045
2013-07-12 14:35:55 +10:00
Paul Borman
5930649306 json: unmarshal types that are byte slices.
The json package cheerfully would marshal

        type S struct {
                IP net.IP
        }

but would give an error when unmarshalling.  This change allows any
type whose concrete type is a byte slice to be unmarshalled from a
string.

Fixes #5086.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11161044
2013-07-11 22:34:09 -04:00
Andrew Gerrand
825373e4f0 encoding/xml: fix typo in docs
Fixes #5843.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/11073043
2013-07-10 10:14:31 +10:00
Oliver Hookins
daf81ae78e encoding/json: Correct description of stateNeg function.
R=golang-dev, dave, adg
CC=golang-dev
https://golang.org/cl/10862045
2013-07-05 14:26:09 +10:00
Rob Pike
0bc7e79afd all: excise some warts found by vet -shadow
These are not erroneous, just poor or confusing.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/10448043
2013-06-20 16:14:40 -07:00
Gerasimos Dimitriadis
02a891b30b asn1: Improved encoding/decoding for OID types
The first identifier in an Object Identifer must be between 0 and 2
inclusive. The range of values that the second one can take depends
on the value of the first one.
The two first identifiers are not necessarily encoded in a single octet,
but in a varint.

R=golang-dev, agl
CC=golang-dev
https://golang.org/cl/10140046
2013-06-10 18:14:47 -04:00
Adam Langley
eec014de66 encoding/asn1: harmonise error prefixes.
This change ensures that error messages always start with "asn1: ".

R=golang-dev, gedimitr
CC=golang-dev
https://golang.org/cl/9751043
2013-06-04 19:51:26 -04:00
Ian Lance Taylor
941db1ed39 encoding/gob: consistently use unsafe.Pointer for pointer values
Fixes #5621.

R=golang-dev, cshapiro, r, fullung
CC=golang-dev
https://golang.org/cl/9988043
2013-06-04 06:20:57 -07:00
Gerasimos Dimitriadis
af48543c54 asn1: Stricter checks for DER encoded booleans
According to X.690, only 0 and 255 are allowed as values
for encoded booleans. Also added some test for parsing
booleans

R=golang-dev, agl, r
CC=golang-dev
https://golang.org/cl/9692043
2013-05-24 12:37:42 -04:00
Brad Fitzpatrick
f1583bb956 encoding/json: allocate less in NewEncoder
The *Encoder is almost always garbage. It doesn't need an
encodeState inside of it (and its bytes.Buffer), since it's
only needed locally inside of Encode.

benchmark                 old ns/op    new ns/op    delta
BenchmarkEncoderEncode         2562         2553   -0.35%

benchmark                 old bytes    new bytes    delta
BenchmarkEncoderEncode          283          102  -63.96%

R=r
CC=gobot, golang-dev
https://golang.org/cl/9365044
2013-05-14 15:50:46 -07:00
Shenghou Ma
5c20a4f260 encoding/json: document that marshaling invalid utf-8 sequence will return error
Also added docs for InvalidUTF8Error.
Fixes #5360.

R=golang-dev, adg, r
CC=golang-dev
https://golang.org/cl/8926046
2013-04-30 11:21:48 +08:00
Rob Pike
88f9ab8926 encoding/json: documentation regarding anonymous fields.
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/8545046
2013-04-11 12:46:23 -07:00
Rob Pike
5fd708c000 encoding/json: different decision on tags and shadowing
If there are no tags, the rules are the same as before.
If there is a tagged field, choose it if there is exactly one
at the top level of all fields.
More tests. The old tests were clearly inadequate, since
they all pass as is. The new tests only work with the new code.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/8617044
2013-04-10 13:05:34 -07:00
Rob Pike
357e37dc94 encoding/json: fix handling of anonymous fields
The old code was incorrect and also broken. It passed the tests by accident.
The new algorithm is:
        1) Sort the fields in order of names.
        2) For all fields with the same name, sort in increasing depth.
        3) Choose the single field with shortest depth.
If any of the fields of a given name has a tag, do the above using
tagged fields of that name only.
Fixes #5245.

R=iant
CC=golang-dev
https://golang.org/cl/8583044
2013-04-09 15:00:21 -07:00
Russ Cox
f6d0adedb6 build: remove dead code
R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7877045
2013-03-22 17:28:22 -04:00
Rob Pike
f29b091110 encoding/gob: delete dead code.
R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7834047
2013-03-22 14:22:55 -07:00
Olivier Saingre
f74eb6dbf7 encoding/xml: rewrite invalid code points to U+FFFD in Marshal, Escape
Fixes #4235.

R=rsc, dave, r, dr.volker.dobler
CC=golang-dev
https://golang.org/cl/7438051
2013-03-13 23:26:03 -04:00
Rick Arnold
cb8aebf19d encoding/json: properly handle extra objects with fixed size arrays
If a fixed size array is passed in as the decode target and the JSON
to decode has extra array elements that are objects, then previously
the decoder would return a "data changing underfoot" error.

Fixes #3717.

R=golang-dev, adg, rsc
CC=golang-dev
https://golang.org/cl/7490046
2013-03-13 14:53:03 -04:00
Russ Cox
bdf8bf6adc encoding/xml: predefine xml name space prefix
Also change prefix generation to use more human-friendly prefixes.

Fixes #5040.

R=golang-dev, r, bradfitz
CC=golang-dev
https://golang.org/cl/7777047
2013-03-13 14:36:42 -04:00
Russ Cox
bfe80e21e4 encoding/xml: reject > chain with non-element
Fixes #5033.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7764044
2013-03-12 16:42:25 -04:00
Russ Cox
4dd3e1e844 encoding/xml: name space bug fixes
If two fields have the same name but different explicit name spaces,
treat as non-conflicting. This allows parsing common XML formats
that have ns1:tag and ns2:tag in the same XML element.
Fixes #4691.

Allow setting the default name space for unadorned tags, by
writing to Decoder.DefaultSpace. This allows turned the job of
parsing common XML formats that have tag and ns2:tag in the
same XML element into the first case by setting DefaultSpace="ns1".
Fixes #3703.

Use name space attributes when decoding.
Attach name space to attributes when encoding.
Could be done with fewer annotations, but semantically correct as is.
Fixes #3526.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7227056
2013-03-12 11:46:12 -04:00
Philip K. Warren
b4237b5997 encoding/base32, encoding/base64: fix issues with decoder whitespace handling
Adds a new reader to filter newlines, which fixes errors seen in the
decoder chunking code. Found additional issues with whitespace handling
after the first padding character.
Fixes #4779.

R=minux.ma, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/7311069
2013-03-12 01:50:10 -04:00
Russ Cox
019754ed40 encoding/xml: fix spurious "no semicolon" in error
Noticed while doing other XML investigations.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/7550045
2013-03-12 00:29:36 -04:00
Russ Cox
aa81eb5901 encoding/xml: allow embedded non-structs
The old code just assumed that the only thing
you can embed is a struct. Not true.

Fixes #3803.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7743043
2013-03-11 23:58:20 -04:00
Nigel Tao
96e0c0c764 encoding/base32, encoding/base64: a small stack-space optimization.
R=dsymonds, dave
CC=golang-dev
https://golang.org/cl/7568045
2013-03-12 11:24:24 +11:00
Nigel Tao
79d06d7286 encoding/base32: don't panic when decoding "AAAA==".
Edit encoding/base64's internals and tests to match encoding/base32.

Properly handling line breaks in padding is left for another CL.

R=dsymonds
CC=golang-dev
https://golang.org/cl/7693044
2013-03-12 11:07:36 +11:00
Brad Fitzpatrick
e15c0ac693 all: remove now-unnecessary unreachable panics
Take advantage of the new terminating statement rule.

R=golang-dev, r, gri
CC=golang-dev
https://golang.org/cl/7712044
2013-03-11 14:16:55 -07:00
Albert Strasheim
0a71a5b029 all: Skip AllocsPerRun tests if GOMAXPROCS>1.
Fixes #4974.

R=rsc, bradfitz, r
CC=golang-dev
https://golang.org/cl/7545043
2013-03-06 15:52:32 -08:00
Russ Cox
349cc74867 encoding/gob: fix copyright
R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7423046
2013-02-28 13:30:59 -08:00
Rob Pike
707ab1347f all: fix some vet-found printf errors
R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7393059
2013-02-25 12:43:03 -08:00
Olivier Saingre
afde71cfbd encoding/xml: make sure Encoder.Encode reports Write errors.
Fixes #4112.

R=remyoudompheng, daniel.morsing, dave, rsc
CC=golang-dev
https://golang.org/cl/7085053
2013-02-20 14:41:23 -08:00
Russ Cox
2b9787c2f3 encoding/binary: make type error more specific
Right now it says 'invalid type S' for a struct type S.
Instead, say which type inside the struct is the problem.

Fixes #4825.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/7301102
2013-02-15 13:12:28 -05:00
Russ Cox
30359a55c2 encoding/json: document and test use of unicode.ReplacementChar
Fixes #4783.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7314099
2013-02-14 14:56:01 -05:00
Russ Cox
d340a89d9c encoding/json: roll back Unmarshal optimization + test
The second attempt at the Unmarshal optimization allowed
panics to get out of the json package. Add test for that bug
and remove the optimization.

Let's stop trying to optimize Unmarshal.

Fixes #4784.

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/7300108
2013-02-14 14:46:15 -05:00
Shenghou Ma
83da2014a8 encoding/xml: fix htmlAutoClose and its generating script
Thanks Mitică for reporting this.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/7308081
2013-02-13 02:27:42 +08:00
Shivakumar GN
848d10f06c xml: omit newline at beginning of MarshalIndent output
(Still valid XML.)

Fixes #3354.

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7288047
2013-02-03 11:21:07 -05:00
Kyle Lemons
9bfd3c3937 testing: add AllocsPerRun
This CL also replaces similar loops in other stdlib
package tests with calls to AllocsPerRun.

Fixes #4461.

R=minux.ma, rsc
CC=golang-dev
https://golang.org/cl/7002055
2013-02-02 22:52:29 -05:00
Russ Cox
31fafa5081 encoding/base64: fix test for ReadFull change
R=golang-dev
CC=golang-dev
https://golang.org/cl/7249045
2013-01-31 14:42:56 -08:00
Russ Cox
956cd0059c encoding/json: document case-insensitive Unmarshal key matching
Fixes #4664.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7237060
2013-01-31 07:49:23 -08:00
Rick Arnold
eea0f19990 encoding/json: improve performance of Unmarshal on primitive types
Attempt 2. The first fix was much faster but ignored syntax errors.

benchmark                      old ns/op    new ns/op    delta
BenchmarkCodeEncoder            74993543     72982390   -2.68%
BenchmarkCodeMarshal            77811181     75610637   -2.83%
BenchmarkCodeDecoder           213337123    190144982  -10.87%
BenchmarkCodeUnmarshal         212180972    190394852  -10.27%
BenchmarkCodeUnmarshalReuse    202113428    182106660   -9.90%
BenchmarkUnmarshalString            1343          919  -31.57%
BenchmarkUnmarshalFloat64           1149          908  -20.97%
BenchmarkUnmarshalInt64              967          778  -19.54%
BenchmarkSkipValue              28851581     28414125   -1.52%

benchmark                       old MB/s     new MB/s  speedup
BenchmarkCodeEncoder               25.88        26.59    1.03x
BenchmarkCodeMarshal               24.94        25.66    1.03x
BenchmarkCodeDecoder                9.10        10.21    1.12x
BenchmarkCodeUnmarshal              9.15        10.19    1.11x
BenchmarkSkipValue                 69.05        70.11    1.02x

Fixes #3949.

R=rsc
CC=golang-dev
https://golang.org/cl/7231058
2013-01-30 17:53:48 -08:00
Andrey Mirtchovski
e579395905 encoding/json: properly unmarshal empty arrays.
The JSON unmarshaller failed to allocate an array when there
are no values for the input causing the `[]` unmarshalled
to []interface{} to generate []interface{}(nil) rather than
[]interface{}{}. This wasn't caught in the tests because Decode()
works correctly and because jsonBig never generated zero-sized
arrays. The modification to scanner_test.go quickly triggers
the error:

without the change to decoder.go, but with the change to scanner_test.go:

$ go test
--- FAIL: TestUnmarshalMarshal (0.10 seconds)
decode_test.go:446:		Marshal jsonBig
scanner_test.go:206:	diverge at 70: «03c1OL6$":null},{"[=» vs «03c1OL6$":[]},{"[=^\»
FAIL
exit status 1
FAIL	encoding/json	0.266s

Also added a simple regression to decode_test.go.

R=adg, dave, rsc
CC=golang-dev
https://golang.org/cl/7196050
2013-01-30 09:10:32 -08:00